]> mj.ucw.cz Git - libucw.git/commitdiff
Another thing about the C standard I didn't know: passing a va_list to
authorMartin Mares <mj@ucw.cz>
Wed, 14 Sep 2005 09:19:17 +0000 (09:19 +0000)
committerMartin Mares <mj@ucw.cz>
Wed, 14 Sep 2005 09:19:17 +0000 (09:19 +0000)
a library function (e.g., snprintf()) can destroy it. Need to call va_copy() here.

lib/ff-printf.c

index fe9c964283d2a0e6e1eff67b90fd3420e89014b7..aff49eb24de203606553f18edf4b81ae1da69c68 100644 (file)
@@ -17,11 +17,13 @@ vbprintf(struct fastbuf *b, char *msg, va_list args)
 {
   byte *buf;
   int len, r;
+  va_list args2;
 
   len = bdirect_write_prepare(b, &buf);
   if (len >= 16)
     {
-      r = vsnprintf(buf, len, msg, args);
+      va_copy(args2, args);
+      r = vsnprintf(buf, len, msg, args2);
       if (r < 0)
        len = 256;
       else if (r < len)
@@ -38,7 +40,8 @@ vbprintf(struct fastbuf *b, char *msg, va_list args)
   while (1)
     {
       buf = alloca(len);
-      r = vsnprintf(buf, len, msg, args);
+      va_copy(args2, args);
+      r = vsnprintf(buf, len, msg, args2);
       if (r < 0)
        len += len;
       else if (r < len)