From 8acfd88f36fe6bce8b53eee09182f268521bdaba Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 1 Jan 2023 18:39:27 -0800 Subject: [PATCH] sfdpgen spring_electrical_embedding_slow: use an agxbuf instead of 'sprintf' This leads to less manual memory management and fewer problems to think about. Gitlab: #1950 --- lib/sfdpgen/spring_electrical.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index 2e850891f..fb64f1580 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -9,6 +9,7 @@ *************************************************************************/ #include "config.h" +#include #include #include #include @@ -692,10 +693,10 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el #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); } @@ -777,10 +778,10 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el #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); } -- 2.40.0