From 2bdb8362f6969384d1c2a4c0ee6bfef5e60e85c5 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 14 Sep 2005 09:19:17 +0000 Subject: [PATCH] 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. --- lib/ff-printf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) -- 2.39.2