Skip to content

Commit

Permalink
fix memory crash due to wrong output data length for plucker, havel &…
Browse files Browse the repository at this point in the history
… badouel ray-tracer when basisorder is 0
  • Loading branch information
ShijieYan committed Aug 25, 2019
1 parent 2f9a45c commit 4dc1228
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/simpmesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void mesh_filenames(const char *format,char *foutput,mcconfig *cfg){

void mesh_loadnode(tetmesh *mesh,mcconfig *cfg){
FILE *fp;
int tmp,len,i,datalen;
int tmp,len,i;
char fnode[MAX_PATH_LENGTH];
mesh_filenames("node_%s.dat",fnode,cfg);
if((fp=fopen(fnode,"rt"))==NULL){
Expand All @@ -187,8 +187,6 @@ void mesh_loadnode(tetmesh *mesh,mcconfig *cfg){
fclose(fp);
if(cfg->method==rtBLBadouelGrid)
mesh_createdualmesh(mesh,cfg);
datalen=(cfg->method==rtBLBadouelGrid) ? cfg->crop0.z : ( (cfg->basisorder) ? mesh->nn : mesh->ne);
mesh->weight=(double *)calloc(sizeof(double)*datalen,cfg->maxgate*cfg->srcnum);
}

void mesh_createdualmesh(tetmesh *mesh,mcconfig *cfg){
Expand Down Expand Up @@ -286,7 +284,7 @@ void mesh_loadmedia(tetmesh *mesh,mcconfig *cfg){

void mesh_loadelem(tetmesh *mesh,mcconfig *cfg){
FILE *fp;
int tmp,len,i,j;
int tmp,len,i,j,datalen;
int *pe;
char felem[MAX_PATH_LENGTH];

Expand All @@ -303,9 +301,9 @@ void mesh_loadelem(tetmesh *mesh,mcconfig *cfg){

mesh->elem=(int *)malloc(sizeof(int)*mesh->elemlen*mesh->ne);
mesh->type=(int *)malloc(sizeof(int )*mesh->ne);
if(!cfg->basisorder)
if(cfg->method==rtBLBadouel)
mesh->weight=(double *)calloc(sizeof(double)*mesh->ne,cfg->maxgate*cfg->srcnum);

datalen=(cfg->method==rtBLBadouelGrid) ? cfg->crop0.z : ( (cfg->basisorder) ? mesh->nn : mesh->ne);
mesh->weight=(double *)calloc(sizeof(double)*datalen,cfg->maxgate*cfg->srcnum);

for(i=0;i<mesh->ne;i++){
pe=mesh->elem+i*mesh->elemlen;
Expand Down

0 comments on commit 4dc1228

Please sign in to comment.