From: Matthew Fernandez Date: Sun, 15 Jan 2023 22:13:19 +0000 (-0800) Subject: graphml2gv nameOf: use an agxbuf instead of raw char buffer for names X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc74a76a380f49059a6e5cb0d15f4461c11a67db;p=graphviz graphml2gv nameOf: use an agxbuf instead of raw char buffer for names This leads to slightly simpler code and fewer things to worry about. Tihs is the equivalent of cd2f8dfd34d4a4ddae1bb94b72098c05d73cfd4e. Gitlab: #1950 --- diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index e9f08944c..4b508788b 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -15,6 +15,7 @@ #include "convert.h" +#include #include #include #include @@ -481,18 +482,12 @@ static void initargs(int argc, char **argv) outFile = stdout; } -static char* -nameOf (char* name, int cnt) -{ - static char* buf = 0; - +static char *nameOf(agxbuf *buf, char *name, int cnt) { if (*name == '\0') return name; if (cnt) { - if (!buf) - buf = gv_calloc(strlen(name) + 32, sizeof(char)); // 32 to handle any integer plus null byte - sprintf (buf, "%s%d", name, cnt); - return buf; + agxbprint(buf, "%s%d", name, cnt); + return agxbuse(buf); } else return name; @@ -508,9 +503,10 @@ int main(int argc, char **argv) int rv = 0, gcnt = 0; #ifdef HAVE_EXPAT + agxbuf buf = {0}; initargs(argc, argv); while ((inFile = getFile())) { - while ((graph = graphml_to_gv(nameOf(gname, gcnt), inFile, &rv))) { + while ((graph = graphml_to_gv(nameOf(&buf, gname, gcnt), inFile, &rv))) { gcnt++; if (prev) agclose(prev); @@ -525,6 +521,7 @@ int main(int argc, char **argv) stack_reset(&Gstack); + agxbfree(&buf); graphviz_exit(rv); #else fputs("graphml2gv: not configured for conversion from GXL to GV\n", stderr);