]> granicus.if.org Git - graphviz/commitdiff
gv2gxl createGraphId: replace char buffer with an agxbuf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 22 Jan 2023 18:57:40 +0000 (10:57 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 28 Jan 2023 06:46:29 +0000 (22:46 -0800)
This removes an assumption that `SMALLBUF` is large enough to fit the printed
string. Performance should be unaffected as agxbuf can store a string of the
length printed here inline.

Gitlab: related to #1950

cmd/tools/gv2gxl.c

index e72dc84fc8a279e25acd91c8c0f2cd1e12404305..cdd1ebfb43db0063c6c0e8c1f9e06f21af5c4e5f 100644 (file)
@@ -202,12 +202,16 @@ static char *addid(Dt_t * ids, char *id)
 static char *createGraphId(Dt_t * ids)
 {
     static int graphIdCounter = 0;
-    char buf[SMALLBUF];
+    agxbuf buf = {0};
+    char *name;
 
     do {
-       snprintf(buf, sizeof(buf), "G_%d", graphIdCounter++);
-    } while (idexists(ids, buf));
-    return addid(ids, buf);
+       agxbprint(&buf, "G_%d", graphIdCounter++);
+       name = agxbuse(&buf);
+    } while (idexists(ids, name));
+    char *rv = addid(ids, name);
+    agxbfree(&buf);
+    return rv;
 }
 
 static char *createNodeId(Dt_t * ids)