Once a va_list has been iterated over one must reset it to the start. So make a copy so we can call vsnprintf() more than once in case we have to reallocate the buffer. Also clearly separate the vstrfmtmake() part from the log writing one in xprintf().
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- programs/winetest/util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/programs/winetest/util.c b/programs/winetest/util.c index af625e7d971..ea67a2d252c 100644 --- a/programs/winetest/util.c +++ b/programs/winetest/util.c @@ -66,7 +66,10 @@ static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap) p = HeapAlloc(GetProcessHeap(), 0, size); if (!p) return NULL; while (1) { - n = vsnprintf (p, size, fmt, ap); + va_list local_ap; + va_copy(local_ap, ap); + n = vsnprintf (p, size, fmt, local_ap); + va_end(local_ap); if (n < 0) size *= 2; /* Windows */ else if ((unsigned)n >= size) size = n+1; /* glibc */ else break; @@ -110,8 +113,9 @@ void xprintf (const char *fmt, ...)
va_start (ap, fmt); buffer = vstrfmtmake (&size, fmt, ap); - head = buffer; va_end (ap); + + head = buffer; while (size) { if (!WriteFile( logfile, head, size, &written, NULL )) report (R_FATAL, "Can't write logs: %u", GetLastError());
Francois Gouget fgouget@codeweavers.com writes:
Once a va_list has been iterated over one must reset it to the start. So make a copy so we can call vsnprintf() more than once in case we have to reallocate the buffer. Also clearly separate the vstrfmtmake() part from the log writing one in xprintf().
Signed-off-by: Francois Gouget fgouget@codeweavers.com
programs/winetest/util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
va_copy is not portable and we try to avoid it.