]> granicus.if.org Git - graphviz/commitdiff
fix handling of varargs in gvprintf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Oct 2020 16:43:24 +0000 (09:43 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 31 Oct 2020 01:46:51 +0000 (18:46 -0700)
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.

lib/gvc/gvdevice.c

index 145f99a7f8c5e3d0bd4fe6c51d210592781c24e6..ccf8e46f4926c494b2e56014f528f01701ea4cd9 100644 (file)
@@ -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