From cc686d8e1612a284f794dd2502a6fa2d6656a60c Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 22 Jan 2023 10:57:40 -0800 Subject: [PATCH] gv2gxl createNodeId: 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 --- cmd/tools/gv2gxl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/tools/gv2gxl.c b/cmd/tools/gv2gxl.c index cdd1ebfb4..a699f4ab0 100644 --- a/cmd/tools/gv2gxl.c +++ b/cmd/tools/gv2gxl.c @@ -23,8 +23,6 @@ #include #include -#define SMALLBUF 128 - #define EMPTY(s) ((s == 0) || (*s == '\0')) #define SLEN(s) (sizeof(s)-1) @@ -217,12 +215,16 @@ static char *createGraphId(Dt_t * ids) static char *createNodeId(Dt_t * ids) { static int nodeIdCounter = 0; - char buf[SMALLBUF]; + agxbuf buf = {0}; + char *name; do { - snprintf(buf, sizeof(buf), "N_%d", nodeIdCounter++); - } while (idexists(ids, buf)); - return addid(ids, buf); + agxbprint(&buf, "N_%d", nodeIdCounter++); + name = agxbuse(&buf); + } while (idexists(ids, name)); + char *rv = addid(ids, name); + agxbfree(&buf); + return rv; } static char *mapLookup(Dt_t * nm, char *name) -- 2.40.0