From: Matthew Fernandez Date: Sat, 24 Oct 2020 16:43:24 +0000 (-0700) Subject: fix handling of varargs in gvprintf X-Git-Tag: 2.46.0~20^2^2~4^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c04c990d93ff5cb43ef184ed11c2c0bad69c523d;p=graphviz fix handling of varargs in gvprintf It is not safe to re-va_start a va_list the way this code was previously operating. This probably worked by coincidence on platforms like x86-64. --- diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 145f99a7f..ccf8e46f4 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -398,8 +398,14 @@ void gvprintf(GVJ_t * job, const char *format, ...) va_start(argp, format); #ifdef HAVE_VSNPRINTF - len = vsnprintf((char *)buf, BUFSIZ, format, argp); + { + va_list argp2; + va_copy(argp2, argp); + len = vsnprintf((char *)buf, BUFSIZ, format, argp2); + va_end(argp2); + } if (len < 0) { + va_end(argp); agerr (AGERR, "gvprintf: %s\n", strerror(errno)); return; } @@ -408,8 +414,6 @@ void gvprintf(GVJ_t * job, const char *format, ...) * to write the string without truncation. */ bp = gmalloc(len + 1); - va_end(argp); - va_start(argp, format); len = vsprintf(bp, format, argp); } #else