From 8cf24edc21e70c57d6c4564dbb609e6ab5f007dc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 23 Jun 2025 19:20:00 -0400 Subject: [PATCH] improve error messages and suppress static code analysis warnings --- src/AMOEBA/amoeba_polar.cpp | 4 ++-- src/AMOEBA/fix_amoeba_bitorsion.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/AMOEBA/amoeba_polar.cpp b/src/AMOEBA/amoeba_polar.cpp index 3c51426beb..dc546076b1 100644 --- a/src/AMOEBA/amoeba_polar.cpp +++ b/src/AMOEBA/amoeba_polar.cpp @@ -1376,10 +1376,10 @@ void PairAmoeba::polar_kspace() expterm = 0.0; if (term > -50.0 && hsq != 0.0) { denom = volterm*hsq*bsmod1[i]*bsmod2[j]*bsmod3[k]; - if (hsq) expterm = exp(term) / denom; + if (denom != 0.0) expterm = exp(term) / denom; struc2 = gridfft[n]*gridfft[n] + gridfft[n+1]*gridfft[n+1]; eterm = 0.5 * felec * expterm * struc2; - vterm = (2.0/hsq) * (1.0-term) * eterm; + vterm = (hsq != 0) ? (2.0/hsq) * (1.0-term) * eterm : 0.0; vxx -= h1*h1*vterm - eterm; vyy -= h2*h2*vterm - eterm; vzz -= h3*h3*vterm - eterm; diff --git a/src/AMOEBA/fix_amoeba_bitorsion.cpp b/src/AMOEBA/fix_amoeba_bitorsion.cpp index 9e2decd5c9..23bd88404b 100644 --- a/src/AMOEBA/fix_amoeba_bitorsion.cpp +++ b/src/AMOEBA/fix_amoeba_bitorsion.cpp @@ -112,7 +112,7 @@ FixAmoebaBiTorsion::FixAmoebaBiTorsion(LAMMPS *lmp, int narg, char **arg) : // register with Atom class nmax_previous = 0; - grow_arrays(atom->nmax); + FixAmoebaBiTorsion::grow_arrays(atom->nmax); atom->add_callback(Atom::GROW); atom->add_callback(Atom::RESTART); @@ -730,22 +730,22 @@ void FixAmoebaBiTorsion::read_grid_data(char *bitorsion_file) FILE *fp = nullptr; if (me == 0) { - fp = utils::open_potential(bitorsion_file,lmp,nullptr); + fp = utils::open_potential(bitorsion_file, lmp, nullptr); if (fp == nullptr) - error->one(FLERR,"Cannot open fix amoeba/bitorsion file {}: {}", + error->one(FLERR, Error::NOLASTLINE, "Cannot open fix amoeba/bitorsion file {}: {}", bitorsion_file, utils::getsyserror()); - eof = fgets(line,MAXLINE,fp); - eof = fgets(line,MAXLINE,fp); + (void) fgets(line,MAXLINE,fp); + (void) fgets(line,MAXLINE,fp); eof = fgets(line,MAXLINE,fp); if (eof == nullptr) - error->one(FLERR,"Unexpected end of fix amoeba/bitorsion file"); + error->one(FLERR, Error::NOLASTLINE, "Unexpected end of fix amoeba/bitorsion file"); sscanf(line,"%d",&nbitypes); } MPI_Bcast(&nbitypes,1,MPI_INT,0,world); - if (nbitypes == 0) error->all(FLERR,"Fix amoeba/bitorsion file has no types"); + if (nbitypes == 0) error->all(FLERR, Error::NOLASTLINE, "Fix amoeba/bitorsion file has no types"); // allocate data structs // type index ranges from 1 to Nbitypes, so allocate one larger @@ -763,10 +763,10 @@ void FixAmoebaBiTorsion::read_grid_data(char *bitorsion_file) for (int itype = 1; itype <= nbitypes; itype++) { if (me == 0) { - eof = fgets(line,MAXLINE,fp); + (void) fgets(line,MAXLINE,fp); eof = fgets(line,MAXLINE,fp); if (eof == nullptr) - error->one(FLERR,"Unexpected end of fix amoeba/bitorsion file"); + error->one(FLERR, Error::NOLASTLINE, "Unexpected end of fix amoeba/bitorsion file"); sscanf(line,"%d %d %d",&tmp,&nx,&ny); }