summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-string.c20
-rw-r--r--dbus/dbus-sysdeps.h14
2 files changed, 30 insertions, 4 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index f78d01c9..6a83398d 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -31,6 +31,8 @@
#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
#include "dbus-string-private.h"
#include "dbus-protocol.h"
+/* for DBUS_VA_COPY */
+#include "dbus-sysdeps.h"
/**
* @defgroup DBusString string class
@@ -1013,16 +1015,26 @@ _dbus_string_append_printf_valist (DBusString *str,
{
int len;
char c;
+ va_list args_copy;
+
DBUS_STRING_PREAMBLE (str);
-
+
+ DBUS_VA_COPY (args_copy, args);
+
/* Measure the message length without terminating nul */
len = vsnprintf (&c, 1, format, args);
if (!_dbus_string_lengthen (str, len))
- return FALSE;
-
+ {
+ /* don't leak the copy */
+ va_end (args_copy);
+ return FALSE;
+ }
+
vsprintf (real->str + (real->len - len),
- format, args);
+ format, args_copy);
+
+ va_end (args_copy);
return TRUE;
}
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index da71f99f..5febc6e6 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -306,6 +306,20 @@ void _dbus_set_signal_handler (int sig,
DBusSignalHandler handler);
+/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
+ * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
+ */
+#if !defined (DBUS_VA_COPY)
+# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
+# define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
+# elif defined (DBUS_VA_COPY_AS_ARRAY)
+# define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list))
+# else /* va_list is a pointer */
+# define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2))
+# endif /* va_list is a pointer */
+#endif /* !DBUS_VA_COPY */
+
+
DBUS_END_DECLS;
#endif /* DBUS_SYSDEPS_H */