From: Matthew Fernandez Date: Sat, 14 Jan 2023 23:52:55 +0000 (-0800) Subject: ccomps process: replace 'sprintf' with 'agxbprint' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46b471f6b6031697dbdde784d84574a678f5703c;p=graphviz ccomps process: 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 c1eeaeb04..4199993bc 100644 --- a/cmd/tools/ccomps.c +++ b/cmd/tools/ccomps.c @@ -708,10 +708,10 @@ static int process(Agraph_t * g, char* graphName) return 1; } { - char *name = gv_alloc(sizeof(PFX1) + strlen(graphName)); - sprintf(name, PFX1, graphName); - out = agsubg(g, name, 1); - free(name); + agxbuf name = {0}; + agxbprint(&name, PFX1, graphName); + out = agsubg(g, agxbuse(&name), 1); + agxbfree(&name); } aginit(out, AGRAPH, "graphinfo", sizeof(Agraphinfo_t), TRUE); GD_cc_subg(out) = 1; @@ -733,10 +733,10 @@ static int process(Agraph_t * g, char* graphName) if (ND_mark(n)) continue; { - char *name = gv_alloc(sizeof(PFX2) + strlen(graphName) + 32); - sprintf(name, PFX2, graphName, c_cnt); - out = agsubg(g, name, 1); - free(name); + agxbuf name = {0}; + agxbprint(&name, PFX2, graphName, c_cnt); + out = agsubg(g, agxbuse(&name), 1); + agxbfree(&name); } aginit(out, AGRAPH, "graphinfo", sizeof(Agraphinfo_t), TRUE); GD_cc_subg(out) = 1;