Skip to content

Commit

Permalink
Try dynamically heap allocating 'ex' instead of a stack-allocated VLA…
Browse files Browse the repository at this point in the history
… to avoid ASan stack-overflow
  • Loading branch information
PhilMiller committed Mar 29, 2024
1 parent a76ccdf commit 4bfbca7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/topmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ extern void topmod(FILE *output_fptr, int nstep, int num_topodex_values,
current_time_step, *sump, *sumae, *sumq, stand_alone
added as function input parameters */

double ex[num_topodex_values+1]; //+1 to maintin 1 based array indexing
//NJF TODO consider warning on all program limits here since this is essentially
//"the model" where those assumptions may not be valid...
if(num_topodex_values > WARN_TOPODEX_INCREMENTS){
printf("WARNING: num_topodex_values, %d, is greater than %d\n",
num_topodex_values, WARN_TOPODEX_INCREMENTS);
}
double *ex = malloc(sizeof(double)*(num_topodex_values+1)); //+1 to maintin 1 based array indexing
int ia,ib,in,irof,it,ir;
double rex,cumf,max_contrib_area,ea,rint,acm,df;
double acf,uz,sae,of;
Expand Down Expand Up @@ -364,6 +364,8 @@ for(ia=1;ia<=num_topodex_values;ia++)

}

free(ex);

return;

}
Expand Down

0 comments on commit 4bfbca7

Please sign in to comment.