Vladimir Oleynik pointed out that va_start() twice in the same function
authorRob Landley <rob@landley.net>
Fri, 15 Jun 2007 19:16:46 +0000 (15:16 -0400)
committerRob Landley <rob@landley.net>
Fri, 15 Jun 2007 19:16:46 +0000 (15:16 -0400)
isn't portable (with ppc 4xx as an example of a platform it doesn't work
on).  This is why va_copy exists.

lib/lib.c

index 8430ae6..4e0ef73 100644 (file)
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -126,22 +126,22 @@ void *xstrdup(char *s)
 // Die unless we can allocate enough space to sprintf() into.
 char *xmsprintf(char *format, ...)
 {
-       va_list va;
+       va_list va, va2;
        int len;
        char *ret;
        
-       // How long is it?
-
        va_start(va, format);
+       va_copy(va2, va);
+
+       // How long is it?
        len = vsnprintf(0, 0, format, va);
        len++;
        va_end(va);
 
        // Allocate and do the sprintf()
        ret = xmalloc(len);
-       va_start(va, format);
-       vsnprintf(ret, len, format, va);        
-       va_end(va);
+       vsnprintf(ret, len, format, va2);       
+       va_end(va2);
 
        return ret;
 }