From: Matthew Fernandez Date: Sun, 22 Jan 2023 18:57:40 +0000 (-0800) Subject: gv2gxl createGraphId: replace char buffer with an agxbuf X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=586296cfb71640c75e91696be62cc320ff583b83;p=graphviz gv2gxl createGraphId: replace char buffer with an agxbuf 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 --- diff --git a/cmd/tools/gv2gxl.c b/cmd/tools/gv2gxl.c index e72dc84fc..cdd1ebfb4 100644 --- a/cmd/tools/gv2gxl.c +++ b/cmd/tools/gv2gxl.c @@ -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)