]> granicus.if.org Git - graphviz/commitdiff
remove short buffer path in pov rendering el
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 14 Apr 2021 04:15:18 +0000 (21:15 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 20 Apr 2021 14:49:55 +0000 (07:49 -0700)
C99 vsnprintf semantics let you call the function with a NULL pointer to
discover the required number of bytes to print the given string. With this
ability, there is no longer any advantage to having two paths through this
function.

plugin/core/gvrender_core_pov.c

index f459bcde54f20631024a581be59bcdb7e7790103..b8ea7d1a52ed9b088e9c7aded59c4c3fbbf5f041 100644 (file)
@@ -326,26 +326,22 @@ static char *el(GVJ_t* job, char *template, ...)
 
        return str;
 #else
-       char buf[BUFSIZ];
        int len;
        char *str;
        va_list arglist;
 
        va_start(arglist, template);
-       len = vsnprintf(buf, BUFSIZ, template, arglist);
+       len = vsnprintf(NULL, 0, template, arglist);
        if (len < 0) {
                job->common->errorfn("pov renderer:el - %s\n", strerror(errno));
                str = strdup ("");
        }
-       else if (len >= BUFSIZ) {
+       else {
                str = malloc (len+1);
                va_end(arglist);
                va_start(arglist, template);
                vsprintf(str, template, arglist);
        }
-       else {
-               str = strdup (buf);
-       }
        va_end(arglist);
 
        return str;