r5938: - allow NULL string argument to talloc_vasprintf_append()
authorAndrew Tridgell <tridge@samba.org>
Tue, 22 Mar 2005 05:51:41 +0000 (05:51 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:11:10 +0000 (13:11 -0500)
- default to using va_copy(), thus assuming a modern libc

source/lib/talloc/talloc.c

index 72765448c7912c1af0a432945ea8bcc2fe2a70f2..31796a247ba593955d9f53ab37ebb536d21dd753 100644 (file)
@@ -36,6 +36,8 @@
 #include <stdarg.h>
 #include <stdint.h>
 #include "talloc.h"
+/* assume a modern system */
+#define HAVE_VA_COPY
 #endif
 
 /* use this to force every realloc to change the pointer, to stress test
@@ -946,10 +948,16 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINT
 
 static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
 {      
-       struct talloc_chunk *tc = talloc_chunk_from_ptr(s);
+       struct talloc_chunk *tc;
        int len, s_len;
        va_list ap2;
 
+       if (s == NULL) {
+               return talloc_vasprintf(NULL, fmt, ap);
+       }
+
+       tc = talloc_chunk_from_ptr(s);
+
        VA_COPY(ap2, ap);
 
        s_len = tc->size - 1;