From ff107e911ba74e9424d746faf9f6739c6cb5c072 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 1 Jan 2023 18:39:27 -0800 Subject: [PATCH] sfdpgen spring_electrical_spring_embedding: 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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index caf32a7d2..db5547746 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -1357,10 +1357,10 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D #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); } @@ -1460,10 +1460,10 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D #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