Fix issues for clang-analyzer-8
authorMark Abraham <mark.j.abraham@gmail.com>
Tue, 13 Aug 2019 14:48:40 +0000 (16:48 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 20 Aug 2019 08:38:37 +0000 (10:38 +0200)
pdb2gmx can no longer attempt to add a vsite after issuing a warning
that it cannot convert an atom, instead exiting with a fatal error.

Fixed bug in gmx order -calcdist

Suppressed some analyzer leak warnings of gmock objects. If the leaks
are real, ASAN will really find it, and if not we aren't going to fix
it in gmock.

Change-Id: Ib3290d7722c1e719ce5291cf3db68a87bc7ce89a

34 files changed:
admin/builds/clang-analyzer.py
docs/release-notes/2020/major/tools.rst
src/external/thread_mpi/src/comm.cpp
src/gromacs/analysisdata/tests/mock_datamodule.cpp
src/gromacs/awh/awh.cpp
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/partition.cpp
src/gromacs/ewald/pme_spread.cpp
src/gromacs/fft/fft5d.cpp
src/gromacs/fileio/matio.cpp
src/gromacs/gmxana/gmx_analyze.cpp
src/gromacs/gmxana/gmx_bar.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_mindist.cpp
src/gromacs/gmxana/gmx_msd.cpp
src/gromacs/gmxana/gmx_order.cpp
src/gromacs/gmxana/gmx_wham.cpp
src/gromacs/gmxpreprocess/gen_vsite.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/pdb2gmx.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/listed_forces/manage_threading.cpp
src/gromacs/mdlib/lincs.cpp
src/gromacs/mdlib/mdatoms.cpp
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/rerun.cpp
src/gromacs/mdrun/shellfc.cpp
src/gromacs/mdrunutility/tests/threadaffinitytest.cpp
src/gromacs/mdrunutility/tests/threadaffinitytest.h
src/gromacs/nbnxm/grid.cpp
src/gromacs/pulling/tests/pull.cpp
src/gromacs/selection/compiler.cpp
src/gromacs/tools/pme_error.cpp
src/gromacs/trajectoryanalysis/modules/surfacearea.cpp

index 345ebb4015c9f661ac1ea2a59c3877bb4f668b24..1b1129ef95c332c12777ac3aca0ba55117fcd9ba 100644 (file)
@@ -35,7 +35,7 @@
 # These options need to match the node label in Jenkins and the
 # capabilities in releng/agents.py for the agent where the analysis is
 # intended to run.
-build_options = ['clang-6', 'clang-static-analyzer-6']
+build_options = ['clang-8', 'clang-static-analyzer-8']
 
 # Policy global variables
 use_stdlib_through_env_vars = False
index 3451957b9ce87118c30a3dfae2082af3563b9c61..f07f7624600c6a8ba2c7db5a5f8ad361b16e67b6 100644 (file)
@@ -7,3 +7,8 @@ Improvements to |Gromacs| tools
    Also, please use the syntax :issue:`number` to reference issues on redmine, without the
    a space between the colon and number!
 
+Fixed bug in gmx order -calcdist
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+The reference position for the distance calculation was calculated
+wrongly.
+
index 28464fa1ef924db5a5f0be0b7d956ad33ac17b37..86089ba12a59c1447b5afdbfa44482f9c108c9d6 100644 (file)
@@ -555,8 +555,8 @@ int tMPI_Comm_split(tMPI_Comm comm, int color, int key, tMPI_Comm *newcomm)
     int                 i, j;
     int                 N = tMPI_Comm_N(comm);
     volatile tMPI_Comm *newcomm_list;
-    volatile int        colors[MAX_PREALLOC_THREADS]; /* array with the colors
-                                                         of each thread */
+    volatile int        colors[MAX_PREALLOC_THREADS] = { 0 }; /* array with the colors
+                                                                 of each thread */
     volatile int        keys[MAX_PREALLOC_THREADS];   /* same for keys (only one of
                                                          the threads actually suplies
                                                          these arrays to the comm
index 7fdd647eb6349137bad72480e0ec616da13fecd9..b2551ca65508b29a204dd8539e40b7d12e45a041 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2017,2019, 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.
@@ -536,6 +536,7 @@ MockAnalysisDataModule::setupStaticCheck(const AnalysisDataTestInput &data,
 
     if (bParallel)
     {
+#ifndef __clang_analyzer__
         ::testing::Expectation init =
             EXPECT_CALL(*this, parallelDataStarted(source, _))
                 .WillOnce(Return(true));
@@ -573,6 +574,7 @@ MockAnalysisDataModule::setupStaticCheck(const AnalysisDataTestInput &data,
         }
         EXPECT_CALL(*this, dataFinished())
             .After(framesFinished);
+#endif
     }
     else
     {
index 3d035c3ff8ad6eab3ed8f9bfef30e72b79b43093..98cfaf04a79dd458ab3fd105cad53274f9258146 100644 (file)
@@ -100,19 +100,19 @@ struct BiasCoupledToSystem
     BiasCoupledToSystem(Bias                    bias,
                         const std::vector<int> &pullCoordIndex);
 
-    Bias                   bias;           /**< The bias. */
-    const std::vector<int> pullCoordIndex; /**< The pull coordinates this bias acts on. */
+    Bias                   bias_;           /**< The bias. */
+    const std::vector<int> pullCoordIndex_; /**< The pull coordinates this bias acts on. */
 
     /* Here AWH can be extended to work on other coordinates than pull. */
 };
 
 BiasCoupledToSystem::BiasCoupledToSystem(Bias                    bias,
                                          const std::vector<int> &pullCoordIndex) :
-    bias(std::move(bias)),
-    pullCoordIndex(pullCoordIndex)
+    bias_(std::move(bias)),
+    pullCoordIndex_(pullCoordIndex)
 {
     /* We already checked for this in grompp, but check again here. */
-    GMX_RELEASE_ASSERT(static_cast<size_t>(bias.ndim()) == pullCoordIndex.size(), "The bias dimensionality should match the number of pull coordinates.");
+    GMX_RELEASE_ASSERT(static_cast<size_t>(bias_.ndim()) == pullCoordIndex_.size(), "The bias dimensionality should match the number of pull coordinates.");
 }
 
 Awh::Awh(FILE                 *fplog,
@@ -175,7 +175,7 @@ Awh::Awh(FILE                 *fplog,
         biasCoupledToSystem_.emplace_back(Bias(k, awhParams, awhParams.awhBiasParams[k], dimParams, beta, inputRecord.delta_t, numSharingSimulations, biasInitFilename, thisRankWillDoIO),
                                           pullCoordIndex);
 
-        biasCoupledToSystem_.back().bias.printInitializationToLog(fplog);
+        biasCoupledToSystem_.back().bias_.printInitializationToLog(fplog);
     }
 
     /* Need to register the AWH coordinates to be allowed to apply forces to the pull coordinates. */
@@ -186,7 +186,7 @@ Awh::Awh(FILE                 *fplog,
         std::vector<size_t> pointSize;
         for (auto const &biasCts : biasCoupledToSystem_)
         {
-            pointSize.push_back(biasCts.bias.state().points().size());
+            pointSize.push_back(biasCts.bias_.state().points().size());
         }
         /* Ensure that the shared biased are compatible between simulations */
         biasesAreCompatibleForSharingBetweenSimulations(awhParams, pointSize, multiSimRecord_);
@@ -227,9 +227,9 @@ real Awh::applyBiasForcesAndUpdateBias(int                     ePBC,
          * pull coordinates.
          */
         awh_dvec coordValue = { 0, 0, 0, 0 };
-        for (int d = 0; d < biasCts.bias.ndim(); d++)
+        for (int d = 0; d < biasCts.bias_.ndim(); d++)
         {
-            coordValue[d] = get_pull_coord_value(pull_, biasCts.pullCoordIndex[d], &pbc);
+            coordValue[d] = get_pull_coord_value(pull_, biasCts.pullCoordIndex_[d], &pbc);
         }
 
         /* Perform an AWH biasing step: this means, at regular intervals,
@@ -242,11 +242,11 @@ real Awh::applyBiasForcesAndUpdateBias(int                     ePBC,
          *       to supports bias sharing within a single simulation.
          */
         gmx::ArrayRef<const double> biasForce =
-            biasCts.bias.calcForceAndUpdateBias(coordValue,
-                                                &biasPotential, &biasPotentialJump,
-                                                commRecord_,
-                                                multiSimRecord_,
-                                                t, step, seed_, fplog);
+            biasCts.bias_.calcForceAndUpdateBias(coordValue,
+                                                 &biasPotential, &biasPotentialJump,
+                                                 commRecord_,
+                                                 multiSimRecord_,
+                                                 t, step, seed_, fplog);
 
         awhPotential += biasPotential;
 
@@ -257,9 +257,9 @@ real Awh::applyBiasForcesAndUpdateBias(int                     ePBC,
          * The bias potential is returned at the end of this function,
          * so that it can be added externally to the correct energy data block.
          */
-        for (int d = 0; d < biasCts.bias.ndim(); d++)
+        for (int d = 0; d < biasCts.bias_.ndim(); d++)
         {
-            apply_external_pull_coord_force(pull_, biasCts.pullCoordIndex[d],
+            apply_external_pull_coord_force(pull_, biasCts.pullCoordIndex_[d],
                                             biasForce[d], &mdatoms,
                                             forceWithVirial);
         }
@@ -269,7 +269,7 @@ real Awh::applyBiasForcesAndUpdateBias(int                     ePBC,
             /* We might have skipped updates for part of the grid points.
              * Ensure all points are updated before writing out their data.
              */
-            biasCts.bias.doSkippedUpdatesForAllPoints();
+            biasCts.bias_.doSkippedUpdatesForAllPoints();
         }
     }
 
@@ -288,7 +288,7 @@ std::shared_ptr<AwhHistory> Awh::initHistoryFromState() const
 
         for (size_t k = 0; k < awhHistory->bias.size(); k++)
         {
-            biasCoupledToSystem_[k].bias.initHistoryFromState(&awhHistory->bias[k]);
+            biasCoupledToSystem_[k].bias_.initHistoryFromState(&awhHistory->bias[k]);
         }
 
         return awhHistory;
@@ -321,7 +321,7 @@ void Awh::restoreStateFromHistory(const AwhHistory *awhHistory)
 
     for (size_t k = 0; k < biasCoupledToSystem_.size(); k++)
     {
-        biasCoupledToSystem_[k].bias.restoreStateFromHistory(awhHistory ? &awhHistory->bias[k] : nullptr, commRecord_);
+        biasCoupledToSystem_[k].bias_.restoreStateFromHistory(awhHistory ? &awhHistory->bias[k] : nullptr, commRecord_);
     }
 }
 
@@ -339,7 +339,7 @@ void Awh::updateHistory(AwhHistory *awhHistory) const
 
     for (size_t k = 0; k < awhHistory->bias.size(); k++)
     {
-        biasCoupledToSystem_[k].bias.updateHistory(&awhHistory->bias[k]);
+        biasCoupledToSystem_[k].bias_.updateHistory(&awhHistory->bias[k]);
     }
 }
 
@@ -381,7 +381,7 @@ void Awh::writeToEnergyFrame(int64_t      step,
     int numSubblocks  = 0;
     for (auto &biasCoupledToSystem : biasCoupledToSystem_)
     {
-        numSubblocks += biasCoupledToSystem.bias.numEnergySubblocksToWrite();
+        numSubblocks += biasCoupledToSystem.bias_.numEnergySubblocksToWrite();
     }
     GMX_ASSERT(numSubblocks > 0, "We should always have data to write");
 
@@ -399,7 +399,7 @@ void Awh::writeToEnergyFrame(int64_t      step,
     int energySubblockCount = 0;
     for (auto &biasCoupledToSystem : biasCoupledToSystem_)
     {
-        energySubblockCount += biasCoupledToSystem.bias.writeToEnergySubblocks(&(awhEnergyBlock->sub[energySubblockCount]));
+        energySubblockCount += biasCoupledToSystem.bias_.writeToEnergySubblocks(&(awhEnergyBlock->sub[energySubblockCount]));
     }
 }
 
index 8ec5ce80e5f40436a14f44c062527461dc8bbdac..f9d642e16cfca4dc4808029c120e4f6c014d6f83 100644 (file)
@@ -1288,6 +1288,7 @@ static void setup_neighbor_relations(gmx_domdec_t *dd)
     ivec                    tmp, s;
     gmx_domdec_zones_t     *zones;
     gmx_domdec_ns_ranges_t *izone;
+    GMX_ASSERT(dd->ndim >= 0, "Must have non-negative number of dimensions for DD");
 
     for (d = 0; d < dd->ndim; d++)
     {
index e36f49cf45c1702b79533a009cdc5d1ce87f011a..e789d80160a22c1ad899648956092c3272411d57 100644 (file)
@@ -1744,6 +1744,7 @@ get_zone_pulse_cgs(gmx_domdec_t *dd,
             }
             if (dim_ind == 2 && (zonei == 2 || zonei == 3))
             {
+                GMX_ASSERT(dim1 >= 0 && dim1 < DIM, "Must have a valid dimension index");
                 rn[dim1] += cg_cm[cg][dim1] - c->cr1[zone];
                 tric_sh   = 0;
                 for (i = dim1+1; i < DIM; i++)
@@ -1809,6 +1810,7 @@ get_zone_pulse_cgs(gmx_domdec_t *dd,
             if (bDistMB_pulse)
             {
                 clear_rvec(rb);
+                GMX_ASSERT(dim >= 0 && dim < DIM, "Must have a valid dimension index");
                 rb[dim] += cg_cm[cg][dim] - c->bc[dim_ind] + tric_sh;
                 if (rb[dim] > 0)
                 {
index d21f4c6a240c28faa3ec8ab2dffddeb38eab0c39..8e3b31be21fb6cdbe3fe1ec4d8d8f7adf1d752b4 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #include "pme_grid.h"
@@ -874,6 +875,7 @@ void spread_on_grid(const gmx_pme_t *pme,
 
     nthread = pme->nthread;
     assert(nthread > 0);
+    GMX_ASSERT(grids != nullptr || !bSpread, "If there's no grid, we cannot be spreading");
 
 #ifdef PME_TIME_THREADS
     c1 = omp_cyc_start();
index f1ca537d7b5c5acfb84ef72b3ca88338e4f1881a..6392d3b0937f37976ad891c0aa0ac6846a98d40f 100644 (file)
@@ -273,7 +273,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_
         oK1[i] = (KG*i)/P[1];
         #endif
     }
-    for (i = 0; i < P[0]-1; i++)
+    for (i = 0; P[0] > 0 && i < P[0]-1; i++)
     {
         N0[i] = oN0[i+1]-oN0[i];
         M0[i] = oM0[i+1]-oM0[i];
@@ -282,7 +282,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_
     N0[P[0]-1] = NG-oN0[P[0]-1];
     M0[P[0]-1] = MG-oM0[P[0]-1];
     K0[P[0]-1] = KG-oK0[P[0]-1];
-    for (i = 0; i < P[1]-1; i++)
+    for (i = 0; P[1] > 0 && i < P[1]-1; i++)
     {
         N1[i] = oN1[i+1]-oN1[i];
         M1[i] = oM1[i+1]-oM1[i];
@@ -296,7 +296,8 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_
        C: contiguous dimension, and nP: number of processor in subcommunicator
        for that step */
 
-
+    GMX_ASSERT(prank[0] < P[0], "Must have valid rank within communicator size");
+    GMX_ASSERT(prank[1] < P[1], "Must have valid rank within communicator size");
     pM[0] = M0[prank[0]];
     oM[0] = oM0[prank[0]];
     pK[0] = K1[prank[1]];
index 2eb0897281128df0155e3f6ed1d226219bdd9fdd..0dcf8811049e1ca65ed04f162971f37dc23c783b 100644 (file)
@@ -61,7 +61,7 @@
 using namespace gmx;
 
 static const char mapper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+{}|;:',<.>/?";
-#define NMAP static_cast<long int>(strlen(mapper))
+#define NMAP static_cast<long int>(sizeof(mapper)/sizeof(mapper[0]))
 
 #define MAX_XPM_LINELENGTH 4096
 
index 4e98ff3d98b57c353ed4e8de60eae11f4599ee0b..1dc3769df1912fd5e986ea807546cb321ebe0fdb 100644 (file)
@@ -3,7 +3,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,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -398,6 +398,11 @@ static void average(const char *avfile, int avbar_opt,
  */
 static real optimal_error_estimate(double sigma, const double fitparm[], real tTotal)
 {
+    // When sigma is zero, the fitparm data can be uninitialized
+    if (sigma == 0.0)
+    {
+        return 0;
+    }
     double ss = fitparm[1]*fitparm[0]+(1-fitparm[1])*fitparm[2];
     if ((tTotal <= 0) || (ss <= 0))
     {
@@ -484,10 +489,13 @@ static void estimate_error(const char *eefile, int nb_min, int resol, int n,
         }
         if (sig[s] == 0)
         {
-            ee   = 0;
-            a    = 1;
-            tau1 = 0;
-            tau2 = 0;
+            ee         = 0;
+            a          = 1;
+            tau1       = 0;
+            tau2       = 0;
+            fitparm[0] = 0;
+            fitparm[1] = 0;
+            fitparm[2] = 0;
         }
         else
         {
index eca6efd29573a2d11a7bc4378f1e3d9519c96de8..16d70d70c5176c85244f731fbe5d1ccfca1990e8 100644 (file)
@@ -265,11 +265,19 @@ static gmx_bool lambda_components_check(const lambda_components_t *lc,
     {
         return FALSE;
     }
+    GMX_RELEASE_ASSERT((name != nullptr) || (name_length == 0),
+                       "If name is empty, the length of the substring to examine within it must be zero");
     len = std::strlen(lc->names[index]);
     if (len != name_length)
     {
         return FALSE;
     }
+    if (name_length == 0)
+    {
+        // Everything matches a zero-length substring. This branch is
+        // needed because name could in principle be nullptr.
+        return TRUE;
+    }
     return std::strncmp(lc->names[index], name, name_length) == 0;
 }
 
index 984d9287ce7a9ee1af1ee49996ea3255a29d305d..6601111115daca05e689c475bc95876e4868fc05 100644 (file)
@@ -70,6 +70,7 @@
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 #define e2d(x) ENM2DEBYE*(x)
@@ -810,10 +811,11 @@ static void do_dip(const t_topology *top, int ePBC, real volume,
     gmx_rmpbc_t    gpbc         = nullptr;
 
     gnx_tot = gnx[0];
-    if (ncos > 1)
+    if (ncos == 2)
     {
         gnx_tot += gnx[1];
     }
+    GMX_RELEASE_ASSERT(ncos == 1 || ncos == 2, "Invalid number of groups used with -ncos");
 
     vol_aver = 0.0;
 
index 52cd5148f0fbe05c0ce5c177348c2599b7302df5..1c4752e8a07da6572bea4211bdc9235307e368fc 100644 (file)
@@ -254,6 +254,7 @@ static void calc_dist(real rcut, gmx_bool bPBC, int ePBC, matrix box, rvec x[],
         j1     = nx1;
         index3 = index1;
     }
+    GMX_RELEASE_ASSERT(index1 != nullptr, "Need a valid index for plotting distances");
 
     rmin2 = 1e12;
     rmax2 = -1e12;
@@ -376,6 +377,7 @@ static void dist_plot(const char *fn, const char *afile, const char *dfile,
         }
         else
         {
+            GMX_RELEASE_ASSERT(ng > 1, "Must have more than one group with bMat");
             snew(leg, (ng*(ng-1))/2);
             for (i = j = 0; (i < ng-1); i++)
             {
@@ -492,6 +494,7 @@ static void dist_plot(const char *fn, const char *afile, const char *dfile,
         }
         else
         {
+            GMX_RELEASE_ASSERT(ng > 1, "Must have more than one group when not using -matrix");
             for (i = 1; (i < ng); i++)
             {
                 calc_dist(rcut, bPBC, ePBC, box, x0, gnx[0], gnx[i], index[0], index[i], bGroup,
@@ -799,6 +802,7 @@ int gmx_mindist(int argc, char *argv[])
         }
         gnx[0] = 1;
     }
+    GMX_RELEASE_ASSERT(!bMat || ng > 1, "Must have more than one group with bMat");
 
     if (resfnm)
     {
index f31fd083551d1dfa1b9aab71423b55dd86c33b04..5e6c1d4a64bd455b33d619862e3f3f9e9e19695a 100644 (file)
@@ -800,6 +800,7 @@ static int corr_loop(t_corr *curr, const char *fn, const t_topology *top, int eP
         /* calculate the center of mass */
         if (!gnx_com.empty())
         {
+            GMX_RELEASE_ASSERT(index_com != nullptr, "Center-of-mass removal must have valid index group");
             calc_com(bMol, gnx_com[0], index_com[0], xa[cur], xa[prev], box,
                      &top->atoms, com);
         }
index 1c0ee1af42f52a08259f3517af688a32c619c020..87dda9fbc195807a7064ffe999e4a02753e7099a 100644 (file)
@@ -3,7 +3,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,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -381,9 +381,8 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
 {
     /* if permolecule = TRUE, order parameters will be calculed per molecule
      * and stored in slOrder with #slices = # molecules */
-    rvec *x0,                                    /* coordinates with pbc                           */
-    *x1,                                         /* coordinates without pbc                        */
-          dist;                                  /* vector between two atoms                       */
+    rvec        *x0,                             /* coordinates with pbc                           */
+    *x1;                                         /* coordinates without pbc                        */
     matrix       box;                            /* box (3x3)                                      */
     t_trxstatus *status;
     rvec         cossum,                         /* sum of vector angles for three axes            */
@@ -403,7 +402,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
     int         *slCount;                        /* nr. of atoms in one slice                      */
     real         sdbangle               = 0;     /* sum of these angles                            */
     gmx_bool     use_unitvector         = FALSE; /* use a specified unit vector instead of axis to specify unit normal*/
-    rvec         direction, com, dref, dvec;
+    rvec         direction, com;
     int          comsize, distsize;
     int         *comidx  = nullptr, *distidx = nullptr;
     char        *grpname = nullptr;
@@ -521,18 +520,19 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
             }
             svmul(1.0/comsize, com, com);
         }
+        rvec displacementFromReference;
         if (distcalc)
         {
-            dref[XX] = 0.0; dref[YY] = 0.0; dref[ZZ] = 0.0;
+            rvec dref = { 0.0, 0.0, 0.0 };
             for (j = 0; j < distsize; j++)
             {
-                rvec_inc(dist, x1[distidx[j]]);
+                rvec_inc(dref, x1[distidx[j]]);
             }
             svmul(1.0/distsize, dref, dref);
             if (radial)
             {
-                pbc_dx(&pbc, dref, com, dvec);
-                unitv(dvec, dvec);
+                pbc_dx(&pbc, dref, com, displacementFromReference);
+                unitv(displacementFromReference, displacementFromReference);
             }
         }
 
@@ -562,6 +562,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
 
                 if (bUnsat)
                 {
+                    rvec dist;
                     /* Using convention for unsaturated carbons */
                     /* first get Sz, the vector from Cn to Cn+1 */
                     rvec_sub(x1[a[index[i+1]+j]], x1[a[index[i]+j]], dist);
@@ -583,6 +584,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
                 }
                 else
                 {
+                    rvec dist;
                     /* get vector dist(Cn-1,Cn+1) for tail atoms */
                     rvec_sub(x1[a[index[i+1]+j]], x1[a[index[i-1]+j]], dist);
                     length = norm(dist); /* determine distance between two atoms */
@@ -660,7 +662,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
                     if (radial)
                     {
                         /* bin order parameter by arc distance from reference group*/
-                        arcdist            = gmx_angle(dvec, direction);
+                        arcdist            = gmx_angle(displacementFromReference, direction);
                         (*distvals)[j][i] += arcdist;
                     }
                     else if (i == 1)
@@ -669,10 +671,11 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
                         tmpdist = trace(box);  /* should be max value */
                         for (k = 0; k < distsize; k++)
                         {
-                            pbc_dx(&pbc, x1[distidx[k]], x1[a[index[i]+j]], dvec);
-                            /* at the moment, just remove dvec[axis] */
-                            dvec[axis] = 0;
-                            tmpdist    = std::min(tmpdist, norm2(dvec));
+                            rvec displacement;
+                            pbc_dx(&pbc, x1[distidx[k]], x1[a[index[i]+j]], displacement);
+                            /* at the moment, just remove displacement[axis] */
+                            displacement[axis] = 0;
+                            tmpdist            = std::min(tmpdist, norm2(displacement));
                         }
                         //fprintf(stderr, "Min dist %f; trace %f\n", tmpdist, trace(box));
                         (*distvals)[j][i] += std::sqrt(tmpdist);
index c8175ac1b880f57dd79b21d1d33b2ecd54c7d87b..79900c51a2f439a6b09863ba2ae9ee434215b697 100644 (file)
@@ -1232,8 +1232,6 @@ static void getRandomIntArray(int nPull, int blockLength, int* randomArray, gmx:
         }
         randomArray[ipull] = ipullRandom;
     }
-    /*for (ipull=0; ipull<nPull; ipull++)
-       printf("%d ",randomArray[ipull]); printf("\n"); */
 }
 
 /*! \brief Set pull group information of a synthetic histogram
@@ -1641,7 +1639,6 @@ static void do_bootstrapping(const char *fnres, const char* fnprof, const char *
     switch (opt->bsMethod)
     {
         case bsMethod_hist:
-            snew(randomArray, nAllPull);
             printf("\n\nWhen computing statistical errors by bootstrapping entire histograms:\n");
             please_cite(stdout, "Hub2006");
             break;
@@ -1674,6 +1671,7 @@ static void do_bootstrapping(const char *fnres, const char* fnprof, const char *
         {
             case bsMethod_hist:
                 /* bootstrap complete histograms from given histograms */
+                srenew(randomArray, nAllPull);
                 getRandomIntArray(nAllPull, opt->histBootStrapBlockLength, randomArray, &opt->rng);
                 for (i = 0; i < nAllPull; i++)
                 {
index 38537e1a4cafc8ef47501c0a950c00a52d5fe848..dacc3175527870feed2123755f38d5d9bd0d3ff5 100644 (file)
@@ -1558,7 +1558,7 @@ void do_vsites(gmx::ArrayRef<const PreprocessResidue> rtpFFDB, PreprocessingAtom
                const char *ffdir)
 {
 #define MAXATOMSPERRESIDUE 16
-    int                        k, m, i0, ni0, whatres, resind, add_shift, nvsite, nadd;
+    int                        k, m, i0, ni0, whatres, add_shift, nvsite, nadd;
     int                        ai, aj, ak, al;
     int                        nrfound = 0, needed, nrbonds, nrHatoms, Heavy, nrheavies, tpM, tpHeavy;
     int                        Hatoms[4], heavies[4];
@@ -1570,7 +1570,6 @@ void do_vsites(gmx::ArrayRef<const PreprocessResidue> rtpFFDB, PreprocessingAtom
     int                       *o2n, *newvsite_type, *newcgnr, ats[MAXATOMSPERRESIDUE];
     t_atom                    *newatom;
     char                    ***newatomname;
-    char                      *resnm = nullptr;
     int                        cmplength;
     bool                       isN, planarN, bFound;
 
@@ -1661,14 +1660,14 @@ void do_vsites(gmx::ArrayRef<const PreprocessResidue> rtpFFDB, PreprocessingAtom
 
     /* generate vsite constructions */
     /* loop over all atoms */
-    resind = -1;
+    int resind = -1;
     for (int i = 0; (i < at->nr); i++)
     {
         if (at->atom[i].resind != resind)
         {
             resind = at->atom[i].resind;
-            resnm  = *(at->resinfo[resind].name);
         }
+        const char *resnm = *(at->resinfo[resind].name);
         /* first check for aromatics to virtualize */
         /* don't waste our effort on DNA, water etc. */
         /* Only do the vsite aromatic stuff when we reach the
@@ -2028,11 +2027,10 @@ void do_vsites(gmx::ArrayRef<const PreprocessResidue> rtpFFDB, PreprocessingAtom
             }
             if (bWARNING)
             {
-                fprintf(stderr,
-                        "Warning: cannot convert atom %d %s (bound to a heavy atom "
-                        "%s with \n"
-                        "         %d bonds and %d bound hydrogens atoms) to virtual site\n",
-                        i+1, *(at->atomname[i]), tpname, nrbonds, nrHatoms);
+                gmx_fatal(FARGS, "Cannot convert atom %d %s (bound to a heavy atom "
+                          "%s with \n"
+                          "         %d bonds and %d bound hydrogens atoms) to virtual site\n",
+                          i+1, *(at->atomname[i]), tpname, nrbonds, nrHatoms);
             }
             if (bAddVsiteParam)
             {
index 10cb4d9875e5430d2f90a01b292446fead7e3c19..0b30620662926759f9a515686abdbc6fb0556c8f 100644 (file)
@@ -960,6 +960,7 @@ static void read_posres(gmx_mtop_t *mtop,
     }
 
     npbcdim = ePBC2npbcdim(ePBC);
+    GMX_RELEASE_ASSERT(npbcdim <= DIM, "Invalid npbcdim");
     clear_rvec(com);
     if (rc_scaling != erscNO)
     {
index 7657d6171ff094944449a3a80bb6c61cce9099ca..db8a24d4c086de892e1e719694ae10704ccc90c2 100644 (file)
@@ -1750,6 +1750,7 @@ int pdb2gmx::run()
 
         if ((i == 0) || (this_chainnumber != prev_chainnumber) || (bWat_ != bPrevWat_))
         {
+            GMX_RELEASE_ASSERT(pdba_all.pdbinfo, "Must have pdbinfo from reading a PDB file if chain number is changing");
             this_chainstart = pdba_all.atom[i].resind;
             bMerged         = false;
             if (i > 0 && !bWat_)
index c2a54c3f213d40f02f48462f1570e5367b40f0e3..be95157da7b1e6b605d946c6cc13ad99f0cd840c 100644 (file)
@@ -809,9 +809,13 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
         {
             sprintf(err_buf, "nstlog must be non-zero");
             CHECK(ir->nstlog == 0);
-            sprintf(err_buf, "nst-transition-matrix (%d) must be an integer multiple of nstlog (%d)",
-                    expand->nstTij, ir->nstlog);
-            CHECK((expand->nstTij % ir->nstlog) != 0);
+            // Avoid modulus by zero in the case that already triggered an error exit.
+            if (ir->nstlog != 0)
+            {
+                sprintf(err_buf, "nst-transition-matrix (%d) must be an integer multiple of nstlog (%d)",
+                        expand->nstTij, ir->nstlog);
+                CHECK((expand->nstTij % ir->nstlog) != 0);
+            }
         }
     }
 
index d10dd20f60c52cb3d27ff479539c9bb058fc14df..5546f1f040cb3e823ff310dfb552e602d77e5158 100644 (file)
@@ -208,7 +208,8 @@ static void divide_bondeds_over_threads(bonded_threading_t *bt,
 {
     ilist_data_t ild[F_NRE];
 
-    assert(bt->nthreads > 0);
+    GMX_ASSERT(bt->nthreads > 0, "Must have positive number of threads");
+    const int numThreads = bt->nthreads;
 
     bt->haveBondeds      = false;
     int    numType       = 0;
@@ -248,12 +249,12 @@ static void divide_bondeds_over_threads(bonded_threading_t *bt,
         if (nrToAssignToCpuThreads == 0)
         {
             /* No interactions, avoid all the integer math below */
-            for (int t = 0; t <= bt->nthreads; t++)
+            for (int t = 0; t <= numThreads; t++)
             {
                 bt->workDivision.setBound(fType, t, 0);
             }
         }
-        else if (bt->nthreads <= bt->max_nthread_uniform || fType == F_DISRES)
+        else if (numThreads <= bt->max_nthread_uniform || fType == F_DISRES)
         {
             /* On up to 4 threads, load balancing the bonded work
              * is more important than minimizing the reduction cost.
@@ -261,10 +262,10 @@ static void divide_bondeds_over_threads(bonded_threading_t *bt,
 
             const int stride = 1 + NRAL(fType);
 
-            for (int t = 0; t <= bt->nthreads; t++)
+            for (int t = 0; t <= numThreads; t++)
             {
                 /* Divide equally over the threads */
-                int nr_t = (((nrToAssignToCpuThreads/stride)*t)/bt->nthreads)*stride;
+                int nr_t = (((nrToAssignToCpuThreads/stride)*t)/numThreads)*stride;
 
                 if (fType == F_DISRES)
                 {
@@ -314,7 +315,7 @@ static void divide_bondeds_over_threads(bonded_threading_t *bt,
                 int t;
 
                 fprintf(debug, "%16s", interaction_function[f].name);
-                for (t = 0; t < bt->nthreads; t++)
+                for (t = 0; t < numThreads; t++)
                 {
                     fprintf(debug, " %4d",
                             (bt->workDivision.bound(f, t + 1) -
index a9b65cdf8f803f7873b9df24a65ee262148a450c..b67723674ddbe5152ad5490c9e03e6fc91b1f823 100644 (file)
@@ -2356,10 +2356,10 @@ bool constrain_lincs(bool computeRmsd,
             }
         }
 
-        int  p_imax;
-        real ncons_loc;
-        real p_ssd;
-        real p_max = 0;
+        int  p_imax    = 0;
+        real ncons_loc = 0;
+        real p_ssd     = 0;
+        real p_max     = 0;
         if (debug)
         {
             cconerr(*lincsd, xprime, pbc,
index 3ff5a699ae8a416a4d99af0dbe034e8db2470a37..45202fe9edeec380e936b196d0e5e66c93991c47 100644 (file)
@@ -395,6 +395,7 @@ void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir,
             else if (md->cFREEZE)
             {
                 g = md->cFREEZE[i];
+                GMX_ASSERT(opts->nFreeze != nullptr, "Must have freeze groups to initialize masses");
                 if (opts->nFreeze[g][XX] && opts->nFreeze[g][YY] && opts->nFreeze[g][ZZ])
                 {
                     /* Set the mass of completely frozen particles to ALMOST_ZERO
index 316668d6159084e85169e5b045c34435ff41c39c..f5c247089a0bf13c6b622afcae973e45b8e96e9f 100644 (file)
@@ -182,8 +182,7 @@ void gmx::LegacySimulator::do_md()
     gmx_bool                bSumEkinhOld, bDoReplEx, bExchanged, bNeedRepartition;
     gmx_bool                bTemp, bPres, bTrotter;
     real                    dvdl_constr;
-    rvec                   *cbuf        = nullptr;
-    int                     cbuf_nalloc = 0;
+    std::vector<RVec>       cbuf;
     matrix                  lastbox;
     int                     lamnew  = 0;
     /* for FEP */
@@ -1213,13 +1212,8 @@ void gmx::LegacySimulator::do_md()
 
         if (ir->eI == eiVVAK)
         {
-            /* We probably only need md->homenr, not state->natoms */
-            if (state->natoms > cbuf_nalloc)
-            {
-                cbuf_nalloc = state->natoms;
-                srenew(cbuf, cbuf_nalloc);
-            }
-            copy_rvecn(as_rvec_array(state->x.data()), cbuf, 0, state->natoms);
+            cbuf.resize(state->x.size());
+            std::copy(state->x.begin(), state->x.end(), cbuf.begin());
         }
 
         if (c_useGpuUpdateConstrain)
@@ -1279,8 +1273,8 @@ void gmx::LegacySimulator::do_md()
                             );
             wallcycle_start(wcycle, ewcUPDATE);
             trotter_update(ir, step, ekind, enerd, state, total_vir, mdatoms, &MassQ, trotter_seq, ettTSEQ4);
-            /* now we know the scaling, we can compute the positions again again */
-            copy_rvecn(cbuf, as_rvec_array(state->x.data()), 0, state->natoms);
+            /* now we know the scaling, we can compute the positions again */
+            std::copy(cbuf.begin(), cbuf.end(), state->x.begin());
 
             update_coords(step, ir, mdatoms, state, f.arrayRefWithPadding(), fcd,
                           ekind, M, &upd, etrtPOSITION, cr, constr);
index d3937bf09b82f96f19e53ddb91ded81bf94fc54b..b55e456eba5dd31217940b892885a48d8e96087e 100644 (file)
@@ -201,7 +201,7 @@ void gmx::LegacySimulator::do_rerun()
     bool                    doFreeEnergyPerturbation = false;
     unsigned int            force_flags;
     tensor                  force_vir, shake_vir, total_vir, pres;
-    t_trxstatus            *status;
+    t_trxstatus            *status = nullptr;
     rvec                    mu_tot;
     t_trxframe              rerun_fr;
     gmx_localtop_t          top;
index 564dc42fbc2ce87eec5d65becfa0d819df7493f0..8c4e39a6e55c6b73ff0406339e326c51f666741f 100644 (file)
@@ -78,6 +78,7 @@
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
 typedef struct {
@@ -161,6 +162,8 @@ static void predict_shells(FILE *fplog, rvec x[], rvec v[], real dt,
     real                  dt_1, fudge, tm, m1, m2, m3;
     rvec                 *ptr;
 
+    GMX_RELEASE_ASSERT(mass || mtop, "Must have masses or a way to look them up");
+
     /* We introduce a fudge factor for performance reasons: with this choice
      * the initial force on the shells is about a factor of two lower than
      * without
index bb672c096272b507d9c05d4b4f203bb2cd22bd63..49965e17cea0bb6b52c09e9f104a10a282e93e11 100644 (file)
@@ -58,8 +58,10 @@ MockThreadAffinityAccess::MockThreadAffinityAccess()
 {
     using ::testing::_;
     using ::testing::Return;
+#ifndef __clang_analyzer__
     ON_CALL(*this, setCurrentThreadAffinityToCore(_))
         .WillByDefault(Return(true));
+#endif
 }
 
 MockThreadAffinityAccess::~MockThreadAffinityAccess()
index 38ca39ccc9bebb9cefecbbe53a2e7aba9794ac11..501e2a8ee80da91039397fdf29891960d5550226 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "gromacs/hardware/hw_info.h"
 #include "gromacs/mdrunutility/threadaffinity.h"
+#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/logger.h"
 #include "gromacs/utility/physicalnodecommunicator.h"
 #include "gromacs/utility/stringutil.h"
@@ -119,8 +120,12 @@ class ThreadAffinityTestHelper
         void expectAffinitySetThatFails(int core)
         {
             using ::testing::Return;
+#ifndef __clang_analyzer__
             EXPECT_CALL(affinityAccess_, setCurrentThreadAffinityToCore(core))
                 .WillOnce(Return(false));
+#else
+            GMX_UNUSED_VALUE(core);
+#endif
         }
 
         void expectWarningMatchingRegex(const char *re)
index a20cf1249ee008f539c8ed473c74d0323331f69c..fbc52c4bd8e41eb8b21d9b80bd4e0f057c1f027d 100644 (file)
@@ -944,6 +944,7 @@ void Grid::fillCell(GridSetData                    *gridSetData,
 #if NBNXN_SEARCH_SIMD4_FLOAT_X_BB
         if (nbat->XFormat == nbatXYZQ)
         {
+            GMX_ASSERT(bb_work_aligned != nullptr, "Must have valid aligned work structure");
             calc_bounding_box_xxxx_simd4(numAtoms, nbat->x().data() + atomStart*nbat->xstride,
                                          bb_work_aligned, pbb_ptr);
         }
index b56fad0b88d7e049122dfeda906ae879d89936a9..ebf966ea08c6d4eb435411e481bb254051463ff1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018,2019, 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.
@@ -77,7 +77,7 @@ class PullTest : public ::testing::Test
             // PBC stuff
             set_pbc(&pbc, epbc, box);
 
-            GMX_ASSERT(pbc.ndim_ePBC >= 1, "Tests only support PBC along at least x");
+            GMX_ASSERT(pbc.ndim_ePBC >= 1 && pbc.ndim_ePBC <= DIM, "Tests only support PBC along at least x and at most x, y, and z");
 
             real boxSizeZSquared;
             if (pbc.ndim_ePBC > ZZ)
index 5e35fc407e32bbd008f6251776e02edfd58ee7d8..7d43e2f10348aed0a529451838aa4069a2f52448 100644 (file)
 #include "gromacs/selection/indexutil.h"
 #include "gromacs/selection/selection.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
 
@@ -2010,6 +2011,7 @@ evaluate_boolean_minmax_grps(const SelectionTreeElementPointer &sel,
     switch (sel->u.boolt)
     {
         case BOOL_NOT:
+            GMX_ASSERT(g != nullptr, "Need a valid group");
             gmx_ana_index_reserve(gmin, g->isize);
             gmx_ana_index_reserve(gmax, g->isize);
             gmx_ana_index_difference(gmax, g, sel->child->cdata->gmin);
@@ -2043,6 +2045,7 @@ evaluate_boolean_minmax_grps(const SelectionTreeElementPointer &sel,
         case BOOL_OR:
             /* We can assume here that the gmin of children do not overlap
              * because of the way _gmx_sel_evaluate_or() works. */
+            GMX_ASSERT(g != nullptr, "Need a valid group");
             gmx_ana_index_reserve(gmin, g->isize);
             gmx_ana_index_reserve(gmax, g->isize);
             gmx_ana_index_copy(gmin, sel->child->cdata->gmin, false);
index 781b7b99cb3c4670fec1485e0d6a56bf3ac34b58..a4334cef255c4beb3ac7c347ae4473ad9891abf8 100644 (file)
@@ -458,6 +458,8 @@ static real estimate_reciprocal(
     double t1 = 0.0;
 #endif
 
+    GMX_RELEASE_ASSERT(q != nullptr, "Must have charges");
+
     if (seed == 0)
     {
         seed = static_cast<int>(gmx::makeRandomSeed());
index c6fb7776dfcf0d0b40463eacc34bef9f2cc88ebd..dade2e781c910a39c24a10f5529defbfa62cfc7d 100644 (file)
@@ -708,11 +708,14 @@ nsc_dclm_pbc(const rvec *coords, const ArrayRef<const real> &radius, int nat,
     }
     if (mode & FLAG_DOTS)
     {
+        GMX_RELEASE_ASSERT(nu_dots != nullptr, "Must have valid nu_dots pointer");
         *nu_dots = lfnr;
+        GMX_RELEASE_ASSERT(lidots != nullptr, "Must have valid lidots pointer");
         *lidots  = dots;
     }
     if (mode & FLAG_ATOM_AREA)
     {
+        GMX_RELEASE_ASSERT(at_area != nullptr, "Must have valid at_area pointer");
         *at_area = atom_area;
     }
     *value_of_area = area;