Fixed static analyzer warnings
authorErik Lindahl <erik@kth.se>
Sat, 11 Jul 2015 18:54:44 +0000 (20:54 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 17 Jul 2015 04:55:26 +0000 (06:55 +0200)
Removed code that had no effect since ct_estimate was reassigned
in expfit.cpp. Initialize variables that are set/used in different
semi-complex switch statements in angle.cpp, and clarify a
switch statement.

Change-Id: I15bb2942e268eb053644d1f457f136d60bc63cfb

src/gromacs/correlationfunctions/expfit.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp

index 3b201bf2c9798f6a88f3504c8b46190f55aeb3c1..0cc2c148ca0c4be282309d61af26e755e9966d8f 100644 (file)
@@ -862,14 +862,6 @@ real fit_acf(int ncorr, int fitfn, const output_env_t oenv, gmx_bool bVerbose,
     nf_int = std::min(ncorr, (int)(tendfit/dt));
     sum    = print_and_integrate(debug, nf_int, dt, c1, NULL, 1);
 
-    /* Estimate the correlation time for better fitting */
-    ct_estimate = 0.5*c1[0];
-    for (i = 1; (i < ncorr) && (c1[i] > 0); i++)
-    {
-        ct_estimate += c1[i];
-    }
-    ct_estimate *= dt/c1[0];
-
     if (bPrint)
     {
         printf("COR: Correlation time (plain integral from %6.3f to %6.3f ps) = %8.5f ps\n",
index 200aed1924fc44c206c63639f48936e4a74b3823..a8a4e0a358fee5e45edf561c8d767f7b281afb31 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015, 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.
@@ -686,21 +686,38 @@ Angle::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
     {
         rvec  v1, v2;
         rvec  c1, c2;
+
+        // v2 & c2 are conditionally set in the switch statement below, and conditionally
+        // used in a different switch statement later. Apparently the clang static analyzer
+        // thinks there are cases where they can be used uninitialzed (which I cannot find),
+        // but to avoid trouble if we ever change just one of the switch statements it
+        // makes sense to clear them outside the first switch.
+
+        clear_rvec(v2);
+        clear_rvec(c2);
+
         switch (g2type_[0])
         {
             case 'z':
-                clear_rvec(v2);
                 v2[ZZ] = 1.0;
-                clear_rvec(c2);
                 break;
             case 's':
                 copy_rvec(sel2_[g].position(0).x(), c2);
                 break;
+            default:
+                // do nothing
+                break;
         }
+
         dh.selectDataSet(g);
         for (int n = 0; n < angleCount_[g]; ++n, iter1.nextValue(), iter2.nextValue())
         {
             rvec x[4];
+            // x[] will be assigned below based on the number of atoms used to initialize iter1,
+            // which in turn should correspond perfectly to g1type_[0] (which determines how many we read),
+            // but unsurprisingly the static analyzer chokes a bit on that.
+            clear_rvecs(4, x);
+
             real angle;
             // checkSelections() ensures that this reflects all the involved
             // positions.