Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <ian.jauslin@rutgers.edu>2023-04-26 17:15:58 -0400
committerIan Jauslin <ian.jauslin@rutgers.edu>2023-04-26 17:15:58 -0400
commita94c066014fe460e2823dee83debf71d6a8a8f24 (patch)
treeef11f82f100ced83c50ac22d90d1fa16922f0d9b
parentaa8825d9d8022412cd68e887e2e3cf7c10a61ed5 (diff)
Avoid segfaults for empty param string
-rw-r--r--src/navier-stokes.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/navier-stokes.c b/src/navier-stokes.c
index 6387fcf..f0c31ed 100644
--- a/src/navier-stokes.c
+++ b/src/navier-stokes.c
@@ -168,13 +168,15 @@ int eea(
// params
// allocate buffer for params
- char* params=calloc(sizeof(char), strlen(params_string)+1);
- strcpy(params, params_string);
- remove_entry(params, "starting_time");
- remove_entry(params, "init");
- remove_entry(params, "nsteps");
- fprintf(savefile," -p \"%s;starting_time=%lu;nsteps=%lu;init=file:%s\"", params, t+1, (nsteps == 0 ? 0 : nsteps-t-1), savefile_string);
- free(params);
+ if(params_string!=NULL) {
+ char* params=calloc(sizeof(char), strlen(params_string)+1);
+ strcpy(params, params_string);
+ remove_entry(params, "starting_time");
+ remove_entry(params, "init");
+ remove_entry(params, "nsteps");
+ fprintf(savefile," -p \"%s;starting_time=%lu;nsteps=%lu;init=file:%s\"", params, t+1, (nsteps == 0 ? 0 : nsteps-t-1), savefile_string);
+ free(params);
+ }
fprintf(savefile," energy\n");