From: Matthew Fernandez Date: Tue, 26 Apr 2022 05:05:18 +0000 (-0700) Subject: sparse: fix: avoid a use of 'itos' X-Git-Tag: 4.0.0~61^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f6dfcda36ca6d674c33b4c889b276666ca0a1d7;p=graphviz sparse: fix: avoid a use of 'itos' Usage of `itos` in this way relies on lifetime extension of a struct member in an rvalue. While these semantics exist in C11 and C++, they do not in C99. As a result, this causes undefined behavior. This commit effectively reverts 10638c445d1f12bb3fcd0c45946ec8a2e3af60af. Gitlab: #2229 --- diff --git a/lib/sparse/DotIO.c b/lib/sparse/DotIO.c index 284586013..34ec9535b 100644 --- a/lib/sparse/DotIO.c +++ b/lib/sparse/DotIO.c @@ -695,7 +695,9 @@ void attached_clustering(Agraph_t* g, int maxcluster, int clustering_scheme){ for (i = 0; i < nnodes; i++) (clusters)[i]++;/* make into 1 based */ for (n = agfstnode (g); n; n = agnxtnode (g, n)) { i = ND_id(n); - agxset(n, clust_sym, itos((clusters)[i]).str); + char value_buffer[CHARS_FOR_NUL_TERM_INT]; + snprintf(value_buffer, sizeof(value_buffer), "%d", clusters[i]); + agxset(n, clust_sym, value_buffer); } if (Verbose){ fprintf(stderr," no complement clustering info in dot file, using modularity clustering. Modularity = %f, ncluster=%d\n",modularity, nc);