From: Martin Mares Date: Wed, 14 Sep 2005 09:19:17 +0000 (+0000) Subject: Another thing about the C standard I didn't know: passing a va_list to X-Git-Tag: holmes-import~743 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=2bdb8362f6969384d1c2a4c0ee6bfef5e60e85c5;p=libucw.git Another thing about the C standard I didn't know: passing a va_list to a library function (e.g., snprintf()) can destroy it. Need to call va_copy() here. --- diff --git a/lib/ff-printf.c b/lib/ff-printf.c index fe9c9642..aff49eb2 100644 --- a/lib/ff-printf.c +++ b/lib/ff-printf.c @@ -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)