]> granicus.if.org Git - graphviz/commitdiff
ccomps: remove parameter to 'split'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 12 Mar 2022 19:21:45 +0000 (11:21 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Mar 2022 20:06:42 +0000 (13:06 -0700)
This function was retaining a pointer to memory pointed to by its parameter,
`name`, in the global `suffix`. So it is unsafe to call this with anything
except a long lived string. We can make this more obvious/explicit by inlining
the use of `outfile`, the only parameter it is ever called with.

cmd/tools/ccomps.c

index 891b50b9b07336430de32271a663665502d8f327..f23213855f8d9cc18efa69b740bd6895a84a25f2 100644 (file)
@@ -133,19 +133,18 @@ static void usage(int v)
     graphviz_exit(v);
 }
 
-static void split(char *name)
-{
+static void split(void) {
     char *sfx = 0;
 
-    sfx = strrchr(name, '.');
+    sfx = strrchr(outfile, '.');
     if (sfx) {
        suffix = sfx + 1;
-       size_t size = (size_t)(sfx - name);
+       size_t size = (size_t)(sfx - outfile);
        path = xmalloc(size + 1);
-       strncpy(path, name, size);
+       strncpy(path, outfile, size);
        *(path + size) = '\0';
     } else {
-       path = name;
+       path = outfile;
     }
 }
 
@@ -168,7 +167,7 @@ static void init(int argc, char *argv[])
        switch (c) {
        case 'o':
            outfile = optarg;
-           split(outfile);
+           split();
            break;
        case 'C':
            useClusters = 1;