From 4bc77bc4ab7e4b976d7e627a4c371fdd71e7bd2b Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Wed, 10 Jan 2024 16:23:58 -0700 Subject: [PATCH] Fix potential integer overflow in PPPM --- src/KSPACE/pppm.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index 2f5b4fc670..328c2c2362 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -1944,7 +1944,8 @@ void PPPM::poisson_ik() // global energy and virial contribution - double scaleinv = 1.0/(nx_pppm*ny_pppm*nz_pppm); + bigint ngridtotal = (bigint) nx_pppm * ny_pppm * nz_pppm; + double scaleinv = 1.0/(ngridtotal); double s2 = scaleinv*scaleinv; if (eflag_global || vflag_global) { @@ -2145,7 +2146,8 @@ void PPPM::poisson_ad() // global energy and virial contribution - double scaleinv = 1.0/(nx_pppm*ny_pppm*nz_pppm); + bigint ngridtotal = (bigint) nx_pppm * ny_pppm * nz_pppm; + double scaleinv = 1.0/(ngridtotal); double s2 = scaleinv*scaleinv; if (eflag_global || vflag_global) { @@ -3259,7 +3261,8 @@ void PPPM::poisson_groups(int AA_flag) // keep everything in reciprocal space so // no inverse FFTs needed - double scaleinv = 1.0/(nx_pppm*ny_pppm*nz_pppm); + bigint ngridtotal = (bigint) nx_pppm * ny_pppm * nz_pppm; + double scaleinv = 1.0/(ngridtotal); double s2 = scaleinv*scaleinv; // energy