avoid overflow when computing memory address offsets on 64-bit machines

This commit is contained in:
Axel Kohlmeyer
2021-02-05 19:42:07 -05:00
parent e223ea3784
commit 12f49c4c89
4 changed files with 12 additions and 12 deletions

View File

@ -174,9 +174,9 @@ template <class T>
void MyPoolChunk<T>::allocate(int ibin) {
int oldpage = npage;
npage += pagedelta;
freelist = (int *) realloc(freelist,npage*chunkperpage*sizeof(int));
pages = (T **) realloc(pages,npage*sizeof(T *));
whichbin = (int *) realloc(whichbin,npage*sizeof(int));
freelist = (int *) realloc(freelist,sizeof(int)*npage*chunkperpage);
pages = (T **) realloc(pages,sizeof(T *)*npage);
whichbin = (int *) realloc(whichbin,sizeof(int)*npage);
if (!freelist || !pages) {
errorflag = 2;
return;
@ -189,11 +189,11 @@ void MyPoolChunk<T>::allocate(int ibin) {
#if defined(LAMMPS_MEMALIGN)
void *ptr;
if (posix_memalign(&ptr, LAMMPS_MEMALIGN,
chunkperpage*chunksize[ibin]*sizeof(T)))
sizeof(T)*chunkperpage*chunksize[ibin]))
errorflag = 2;
pages[i] = (T *) ptr;
#else
pages[i] = (T *) malloc(chunkperpage*chunksize[ibin]*sizeof(T));
pages[i] = (T *) malloc(sizeof(T)*chunkperpage*chunksize[ibin]);
if (!pages[i]) errorflag = 2;
#endif
}