From: Matthew Fernandez Date: Sat, 28 Jan 2023 16:22:47 +0000 (-0800) Subject: mm2gv makeDotGraph: replace 'sprintf' with 'agxbprint' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b346064dac58165105052a193c43aea2a405497;p=graphviz mm2gv makeDotGraph: replace 'sprintf' with 'agxbprint' Given this function already has an agxbuf that was not in use while needing to construct these temporaries, we can reuse it to avoid allocating a separate buffer on the stack. This also improves safety by avoiding `sprintf`. Gitlab: #1950 --- diff --git a/cmd/tools/mm2gv.c b/cmd/tools/mm2gv.c index e578bf676..3e97a3656 100644 --- a/cmd/tools/mm2gv.c +++ b/cmd/tools/mm2gv.c @@ -85,7 +85,6 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim, Agedge_t *e; int i, j; agxbuf xb; - char buf[BUFS]; char string[BUFS]; Agsym_t *sym = NULL, *sym2 = NULL, *sym3 = NULL; int *ia = A->ia; @@ -124,8 +123,8 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim, } for (i = 0; i < A->m; i++) { - sprintf(buf, "%d", i); - n = agnode(g, buf, 1); + agxbprint(&xb, "%d", i); + n = agnode(g, agxbuse(&xb), 1); agbindrec(n, "nodeinfo", sizeof(Agnodeinfo_t), true); ND_id(n) = i; arr[i] = n; @@ -185,13 +184,13 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim, h = arr[ja[j]]; e = agedge(g, n, h, NULL, 1); if (sym && val) { - sprintf(buf, "%f", val[j]); - agxset(e, sym, buf); + agxbprint(&xb, "%f", val[j]); + agxset(e, sym, agxbuse(&xb)); } if (with_color) { agxset (e, sym2, hue2rgb(.65 * color[j], cstring)); - sprintf(buf, "%f", color[j]); - agxset(e, sym3, buf); + agxbprint(&xb, "%f", color[j]); + agxset(e, sym3, agxbuse(&xb)); } } }