Commit ff7449b2 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

ensure, that we have no division by zero and add an upper limit for bins

parent 13d3903e
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -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;