]> granicus.if.org Git - graphviz/commitdiff
sfdpgen spring_electrical_embedding: use an agxbuf instead of 'sprintf'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 2 Jan 2023 02:39:27 +0000 (18:39 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 14 Jan 2023 17:56:12 +0000 (09:56 -0800)
This leads to less manual memory management and fewer problems to think about.

Gitlab: #1950

lib/sfdpgen/spring_electrical.c

index fb64f158026fb6a2d5129bf3dd8e3bc386078ce0..b06767898d867a9fd6ba4f36f9793906ef141068 100644 (file)
@@ -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);
   }