From: Matthew Fernandez Date: Sat, 14 Jan 2023 23:52:55 +0000 (-0800) Subject: ccomps processClusters: replace 'sprintf' with 'agxbprint' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=820e29793a176d59644c15334076102d1a4afad2;p=graphviz ccomps processClusters: replace 'sprintf' with 'agxbprint' This replaces some error prone manual calculation with a dynamic buffer that handles the calculation of needed allocations. This also potentially saves memory in cases of short strings where an agxbuf can use inline storage. Gitlab: #1950 --- diff --git a/cmd/tools/ccomps.c b/cmd/tools/ccomps.c index 866cb40d9..c1eeaeb04 100644 --- a/cmd/tools/ccomps.c +++ b/cmd/tools/ccomps.c @@ -574,11 +574,12 @@ static int processClusters(Agraph_t * g, char* graphName) return 1; } { - char *name = gv_alloc(sizeof(PFX1) + strlen(graphName)); - sprintf(name, PFX1, graphName); + agxbuf buf = {0}; + agxbprint(&buf, PFX1, graphName); + char *name = agxbuse(&buf); dout = agsubg(dg, name, 1); out = agsubg(g, name, 1); - free(name); + agxbfree(&buf); } aginit(out, AGRAPH, "graphinfo", sizeof(Agraphinfo_t), TRUE); GD_cc_subg(out) = 1; @@ -602,11 +603,12 @@ static int processClusters(Agraph_t * g, char* graphName) if (ND_mark(dn)) continue; { - char *name = gv_alloc(sizeof(PFX2) + strlen(graphName) + 32); - sprintf(name, PFX2, graphName, c_cnt); + agxbuf buf = {0}; + agxbprint(&buf, PFX2, graphName, c_cnt); + char *name = agxbuse(&buf); dout = agsubg(dg, name, 1); out = agsubg(g, name, 1); - free(name); + agxbfree(&buf); } aginit(out, AGRAPH, "graphinfo", sizeof(Agraphinfo_t), TRUE); GD_cc_subg(out) = 1;