From ff7449b29af0010cc124ef65f64b0856bbf37e07 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer <akohlmey@gmail.com> Date: Tue, 2 Oct 2018 12:27:05 -0400 Subject: [PATCH] ensure, that we have no division by zero and add an upper limit for bins --- src/USER-MISC/compute_pressure_cylinder.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/USER-MISC/compute_pressure_cylinder.cpp b/src/USER-MISC/compute_pressure_cylinder.cpp index ebe28d848a..04767eb4c3 100644 --- a/src/USER-MISC/compute_pressure_cylinder.cpp +++ b/src/USER-MISC/compute_pressure_cylinder.cpp @@ -61,17 +61,20 @@ ComputePressureCyl::ComputePressureCyl(LAMMPS *lmp, int narg, char **arg) : Rmax=force->numeric(FLERR,arg[5]); bin_width=force->numeric(FLERR,arg[6]); - if (bin_width<0.0 || bin_width<Rmax) + if ((bin_width <= 0.0) || (bin_width < Rmax)) error->all(FLERR,"Illegal compute pressure/cylinder command"); - if (zhi<zlo || (zhi-zlo)<bin_width) + if ((zhi < zlo) || ((zhi-zlo) < bin_width)) error->all(FLERR,"Illegal compute pressure/cylinder command"); - if (zhi>domain->boxhi[2] || zlo<domain->boxlo[2]) + if ((zhi > domain->boxhi[2]) || (zlo < domain->boxlo[2])) error->all(FLERR,"Illegal compute pressure/cylinder command"); nbins=(int)(Rmax/bin_width); nzbins=(int)((zhi-zlo)/bin_width); - - if (nbins<1 or nzbins<1) + + // NOTE: at 2^22 = 4.2M bins, we will be close to exhausting allocatable + // memory on a 32-bit environment. so we use this as an upper limit. + + if ((nbins < 1) || (nzbins < 1) || (nbins > 2>>22) || (nbins > 2>>22)) error->all(FLERR,"Illegal compute pressure/cylinder command"); array_flag=1; -- GitLab