From 37ff709773929dce2683d1787d211a0ad2c738bd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 16 Oct 2014 15:51:41 +0100 Subject: [PATCH 1/8] DBusError: factor out _dbus_set_error_va --- dbus/dbus-errors.c | 27 ++++++++++++++++++++------- dbus/dbus-internals.h | 6 ++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/dbus/dbus-errors.c b/dbus/dbus-errors.c index 5d8f194..ca7045b 100644 --- a/dbus/dbus-errors.c +++ b/dbus/dbus-errors.c @@ -356,19 +356,35 @@ dbus_set_error (DBusError *error, const char *format, ...) { - DBusRealError *real; - DBusString str; va_list args; - + if (error == NULL) return; /* it's a bug to pile up errors */ _dbus_return_if_error_is_set (error); _dbus_return_if_fail (name != NULL); - + + va_start (args, format); + _dbus_set_error_va (error, name, format, args); + va_end (args); +} + +void +_dbus_set_error_va (DBusError *error, + const char *name, + const char *format, + va_list args) +{ + DBusRealError *real; + DBusString str; + + if (error == NULL) + return; + _dbus_assert (error->name == NULL); _dbus_assert (error->message == NULL); + _dbus_assert (name != NULL); if (!_dbus_string_init (&str)) goto nomem; @@ -384,14 +400,11 @@ dbus_set_error (DBusError *error, } else { - va_start (args, format); if (!_dbus_string_append_printf_valist (&str, format, args)) { _dbus_string_free (&str); - va_end (args); goto nomem; } - va_end (args); } real = (DBusRealError *)error; diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 4658b67..4ad668a 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -373,6 +373,12 @@ dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str); typedef struct { char _assertion[(expr) ? 1 : -1]; } \ _DBUS_PASTE (_DBUS_STATIC_ASSERT_, __LINE__) _DBUS_GNUC_UNUSED +/* in dbus-errors.c */ +void _dbus_set_error_va (DBusError *error, + const char *name, + const char *format, + va_list args); + DBUS_END_DECLS #endif /* DBUS_INTERNALS_H */ -- 2.1.1