correct illegal and uninitialized data access issue

This commit is contained in:
Axel Kohlmeyer 2020-08-18 14:19:57 -04:00
parent 2fea8f888a
commit a537ffabf9
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
2 changed files with 14 additions and 10 deletions

View File

@ -306,10 +306,12 @@ double FixTempCSLD::compute_scalar()
void FixTempCSLD::write_restart(FILE *fp)
{
int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy
double *list;
if (comm->me == 0) list = new double[nsize];
list[0] = energy;
list[1] = comm->nprocs;
double *list = nullptr;
if (comm->me == 0) {
list = new double[nsize];
list[0] = energy;
list[1] = comm->nprocs;
}
double state[103];
random->get_state(state);
MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world);
@ -318,8 +320,8 @@ void FixTempCSLD::write_restart(FILE *fp)
int size = nsize * sizeof(double);
fwrite(&size,sizeof(int),1,fp);
fwrite(list,sizeof(double),nsize,fp);
delete[] list;
}
if (comm->me == 0) delete[] list;
}
/* ----------------------------------------------------------------------

View File

@ -339,10 +339,12 @@ double FixTempCSVR::compute_scalar()
void FixTempCSVR::write_restart(FILE *fp)
{
int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy
double *list;
if (comm->me == 0) list = new double[nsize];
list[0] = energy;
list[1] = comm->nprocs;
double *list = nullptr;
if (comm->me == 0) {
list = new double[nsize];
list[0] = energy;
list[1] = comm->nprocs;
}
double state[103];
random->get_state(state);
MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world);
@ -351,8 +353,8 @@ void FixTempCSVR::write_restart(FILE *fp)
int size = nsize * sizeof(double);
fwrite(&size,sizeof(int),1,fp);
fwrite(list,sizeof(double),nsize,fp);
delete[] list;
}
if (comm->me == 0) delete[] list;
}
/* ----------------------------------------------------------------------