Avoid segfaults for empty param string

This commit is contained in:
Ian Jauslin 2023-04-26 17:15:58 -04:00
parent aa8825d9d8
commit a94c066014

View File

@ -168,6 +168,7 @@ int eea(
// params // params
// allocate buffer for params // allocate buffer for params
if(params_string!=NULL) {
char* params=calloc(sizeof(char), strlen(params_string)+1); char* params=calloc(sizeof(char), strlen(params_string)+1);
strcpy(params, params_string); strcpy(params, params_string);
remove_entry(params, "starting_time"); remove_entry(params, "starting_time");
@ -175,6 +176,7 @@ int eea(
remove_entry(params, "nsteps"); 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); 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); free(params);
}
fprintf(savefile," energy\n"); fprintf(savefile," energy\n");