avoid 32-bit integer overflow when allocating memory for neighbor list copy

This commit is contained in:
Axel Kohlmeyer
2023-04-20 14:42:48 -04:00
parent 83f492a195
commit 39fa2021e2
2 changed files with 6 additions and 6 deletions

View File

@ -391,9 +391,10 @@ void IntelBuffers<flt_t, acc_t>::_grow_nbor_list(NeighList * /*list*/,
free_nbor_list();
_list_alloc_atoms = 1.10 * nlocal;
int nt = MAX(nthreads, _off_threads);
int list_alloc_size = (_list_alloc_atoms + nt * 2 + pack_width - 1) *
get_max_nbors();
lmp->memory->create(_list_alloc, list_alloc_size, "_list_alloc");
bigint list_alloc_size =
(bigint)(_list_alloc_atoms + nt * 2 + pack_width - 1) * (bigint)get_max_nbors();
_list_alloc = (int *) lmp->memory->smalloc(list_alloc_size * sizeof(int), "_list_alloc");
#ifdef _LMP_INTEL_OFFLOAD
if (offload_end > 0) {
int * list_alloc =_list_alloc;
@ -706,7 +707,7 @@ double IntelBuffers<flt_t, acc_t>::memory_usage(const int nthreads)
if (_off_f) tmem += fstride*_off_threads * sizeof(vec3_acc_t);
#endif
tmem += (_list_alloc_atoms + _off_threads) * get_max_nbors() * sizeof(int);
tmem += (bigint)(_list_alloc_atoms + _off_threads) * (bigint)get_max_nbors() * sizeof(int);
tmem += _ntypes * _ntypes * sizeof(int);
tmem += _buf_local_size + (_n_list_ptrs - 1) * _buf_local_size * 2;

View File

@ -63,8 +63,7 @@ void *Memory::smalloc(bigint nbytes, const char *name)
void *ptr = malloc(nbytes);
#endif
if (ptr == nullptr)
error->one(FLERR,"Failed to allocate {} bytes for array {}",
nbytes,name);
error->one(FLERR,"Failed to allocate {} bytes for array {}", nbytes,name);
return ptr;
}