dbus-marshal-validate: Check brackets in signature nest correctly
[platform/upstream/dbus.git] / dbus / dbus-errors.c
index 5d7299f..5a305ca 100644 (file)
@@ -21,6 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+
+#include <config.h>
 #include "dbus-errors.h"
 #include "dbus-internals.h"
 #include "dbus-string.h"
@@ -76,6 +78,8 @@ typedef struct
   
 } DBusRealError;
 
+_DBUS_STATIC_ASSERT (sizeof (DBusRealError) == sizeof (DBusError));
+
 /**
  * Returns a longer message describing an error name.
  * If the error name is unknown, returns the name
@@ -185,9 +189,9 @@ dbus_error_init (DBusError *error)
 {
   DBusRealError *real;
 
-  _dbus_return_if_fail (error != NULL);
+  _DBUS_STATIC_ASSERT (sizeof (DBusError) == sizeof (DBusRealError));
 
-  _dbus_assert (sizeof (DBusError) == sizeof (DBusRealError));
+  _dbus_return_if_fail (error != NULL);
 
   real = (DBusRealError *)error;
   
@@ -231,7 +235,7 @@ dbus_error_free (DBusError *error)
  * must ensure the name and message are global data that won't be
  * freed. You probably want dbus_set_error() instead, in most cases.
  * 
- * @param error the error.or #NULL
+ * @param error the error or #NULL
  * @param name the error name (not copied!!!)
  * @param message the error message (not copied!!!)
  */
@@ -352,8 +356,6 @@ dbus_set_error (DBusError  *error,
                const char *format,
                ...)
 {
-  DBusRealError *real;
-  DBusString str;
   va_list args;
   
   if (error == NULL)
@@ -362,7 +364,26 @@ dbus_set_error (DBusError  *error,
   /* 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_valist (error, name, format, args);
+  va_end (args);
+}
+
+void
+_dbus_set_error_valist (DBusError  *error,
+                        const char *name,
+                        const char *format,
+                        va_list     args)
+{
+  DBusRealError *real;
+  DBusString str;
+
+  _dbus_assert (name != NULL);
+
+  if (error == NULL)
+    return;
+
   _dbus_assert (error->name == NULL);
   _dbus_assert (error->message == NULL);
 
@@ -380,14 +401,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;