From: Matthew Fernandez Date: Mon, 2 Jan 2023 02:39:27 +0000 (-0800) Subject: sfdpgen spring_electrical_embedding: use an agxbuf instead of 'sprintf' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d73eabf367d1d46e01bad34881dd4bd54a7c1fd3;p=graphviz sfdpgen spring_electrical_embedding: use an agxbuf instead of 'sprintf' This leads to less manual memory management and fewer problems to think about. Gitlab: #1950 --- diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index fb64f1580..b06767898 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -869,10 +869,10 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con #ifdef DEBUG_0 { FILE *f; - char fname[10000]; - strcpy(fname,"/tmp/graph_layout_0_"); - sprintf(&(fname[strlen(fname)]), "%d",n); - f = fopen(fname,"w"); + agxbuf fname = {0}; + agxbprint(&fname, "/tmp/graph_layout_0_%d", n); + f = fopen(agxbuse(&fname), "w"); + agxbfree(&fname); export_embedding(f, dim, A, x, NULL); fclose(f); } @@ -995,10 +995,10 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con #ifdef DEBUG_PRINT_0 { FILE *f; - char fname[10000]; - strcpy(fname,"/tmp/graph_layout"); - sprintf(&(fname[strlen(fname)]), "%d",n); - f = fopen(fname,"w"); + agxbuf fname = {0}; + agxbprint(&fname, "/tmp/graph_layout%d", n); + f = fopen(agxbuse(&fname), "w"); + agxbfree(&fname); export_embedding(f, dim, A, x, NULL); fclose(f); }