Fix issues found by static analyzer
authorPaul Bauer <paul.bauer.q@gmail.com>
Wed, 3 Feb 2021 12:07:33 +0000 (13:07 +0100)
committerPaul Bauer <paul.bauer.q@gmail.com>
Wed, 3 Feb 2021 12:07:33 +0000 (13:07 +0100)
Update to version 11 found a few issues that need fixes.

Refs #3897

src/gromacs/essentialdynamics/edsam.cpp
src/gromacs/gmxana/hxprops.cpp
src/gromacs/gmxpreprocess/toppush.cpp
src/gromacs/mdrun/minimize.cpp

index a2071943c93379ccf5cf17ac972850431a08a2ab..4861086a578c846d96284b5bdbee8acb9696047d 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -493,7 +493,7 @@ real calc_radius(const t_eigvec& vec)
         rad += gmx::square((vec.refproj[i] - vec.xproj[i]));
     }
 
-    return rad = sqrt(rad);
+    return sqrt(rad);
 }
 } // namespace
 
index 4698ee3bf178b83b1f5cf371c8da640afce686d8..66e4ddb1357be4c5bdfa758134c2c867122f8027 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -329,30 +329,30 @@ t_bb* mkbbind(const char* fn,
 #define NBB asize(bb_nm)
     t_bb* bb;
     char* grpname;
-    int   ai, i, i0, i1, j, k, rnr, gnx, r0, r1;
+    int   gnx, r0, r1;
 
     fprintf(stderr, "Please select a group containing the entire backbone\n");
     rd_index(fn, 1, &gnx, index, &grpname);
     *nall = gnx;
     fprintf(stderr, "Checking group %s\n", grpname);
     r0 = r1 = atom[(*index)[0]].resind;
-    for (i = 1; (i < gnx); i++)
+    for (int i = 1; (i < gnx); i++)
     {
         r0 = std::min(r0, atom[(*index)[i]].resind);
         r1 = std::max(r1, atom[(*index)[i]].resind);
     }
-    rnr = r1 - r0 + 1;
+    int rnr = r1 - r0 + 1;
     fprintf(stderr, "There are %d residues\n", rnr);
     snew(bb, rnr);
-    for (i = 0; (i < rnr); i++)
+    for (int i = 0; (i < rnr); i++)
     {
         bb[i].N = bb[i].H = bb[i].CA = bb[i].C = bb[i].O = -1;
         bb[i].resno                                      = res0 + i;
     }
 
-    for (i = j = 0; (i < gnx); i++)
+    for (int i = 0; (i < gnx); i++)
     {
-        ai = (*index)[i];
+        int ai = (*index)[i];
         // Create an index into the residue index for the topology.
         int resindex = atom[ai].resind;
         // Create an index into the residues present in the selected
@@ -367,7 +367,8 @@ t_bb* mkbbind(const char* fn,
                 bb[bbindex].H = ai;
             }
         }
-        for (k = 0; (k < NBB); k++)
+        int k = 0;
+        for (; (k < NBB); k++)
         {
             if (std::strcmp(bb_nm[k], *(atomname[ai])) == 0)
             {
@@ -389,7 +390,8 @@ t_bb* mkbbind(const char* fn,
         }
     }
 
-    for (i0 = 0; (i0 < rnr); i0++)
+    int i0 = 0;
+    for (; (i0 < rnr); i0++)
     {
         if ((bb[i0].N != -1) && (bb[i0].H != -1) && (bb[i0].CA != -1) && (bb[i0].C != -1)
             && (bb[i0].O != -1))
@@ -397,7 +399,8 @@ t_bb* mkbbind(const char* fn,
             break;
         }
     }
-    for (i1 = rnr - 1; (i1 >= 0); i1--)
+    int i1 = rnr - 1;
+    for (; (i1 >= 0); i1--)
     {
         if ((bb[i1].N != -1) && (bb[i1].H != -1) && (bb[i1].CA != -1) && (bb[i1].C != -1)
             && (bb[i1].O != -1))
@@ -414,7 +417,7 @@ t_bb* mkbbind(const char* fn,
         i1--;
     }
 
-    for (i = i0; (i < i1); i++)
+    for (int i = i0; (i < i1); i++)
     {
         bb[i].Cprev = bb[i - 1].C;
         bb[i].Nnext = bb[i + 1].N;
@@ -425,13 +428,13 @@ t_bb* mkbbind(const char* fn,
     {
         gmx_fatal(FARGS, "Zero complete backbone residues were found, cannot proceed");
     }
-    for (i = 0; (i < rnr); i++, i0++)
+    for (int i = 0; (i < rnr); i++, i0++)
     {
         bb[i] = bb[i0];
     }
 
     /* Set the labels */
-    for (i = 0; (i < rnr); i++)
+    for (int i = 0; (i < rnr); i++)
     {
         int resindex = atom[bb[i].CA].resind;
         sprintf(bb[i].label, "%s%d", *(resinfo[resindex].name), resinfo[resindex].nr);
index 0abf7106222c7fe3db8fda726557a889759d4313..ba67deb03cfee6ee0693a2bf800f3cb168d6d558 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -566,7 +566,7 @@ void push_at(t_symtab*                  symtab,
                 "to suppress this warning with -maxwarn.",
                 type);
         warning(wi, message);
-        if ((nr = at->setType(nr, symtab, *atom, type, interactionType, batype_nr, atomnr)) == NOTSET)
+        if ((at->setType(nr, symtab, *atom, type, interactionType, batype_nr, atomnr)) == NOTSET)
         {
             auto message = gmx::formatString("Replacing atomtype %s failed", type);
             warning_error_and_exit(wi, message, FARGS);
index b64d5236875ddde6b76b66a5e25696ea09f2b4cb..63aeb8b16852db18fb41117e52c4b67931bf4f02 100644 (file)
@@ -1993,7 +1993,7 @@ void LegacySimulator::do_lbfgs()
     /* Print to log file */
     print_em_start(fplog, cr, walltime_accounting, wcycle, LBFGS);
 
-    do_log = do_ene = do_x = do_f = TRUE;
+    do_log = do_ene = do_f = TRUE;
 
     /* Max number of steps */
     number_steps = inputrec->nsteps;