Fix range check bug in gmx covar
authorPaul Bauer <paul.bauer.q@gmail.com>
Tue, 9 Feb 2021 05:14:34 +0000 (05:14 +0000)
committerArtem Zhmurov <zhmurov@gmail.com>
Tue, 9 Feb 2021 05:14:34 +0000 (05:14 +0000)
Range checking was done the wrong way around.

Fixes #3902

docs/release-notes/2021/2021.1.rst
src/gromacs/gmxana/gmx_covar.cpp

index c7914f9357ac1dd8f7b9c7dedaaf789b68648ad8..93e19dba489ea9035ef9af3c04d01e7168e813fb 100644 (file)
@@ -19,6 +19,13 @@ Fixes where mdrun could behave incorrectly
 Fixes for ``gmx`` tools
 ^^^^^^^^^^^^^^^^^^^^^^^
 
+Fix range checking bug in gmx covar
+"""""""""""""""""""""""""""""""""""
+
+A check was inverted causing range checking to be applied wrong.
+
+:issue:`3902`
+
 Fixes that affect portability
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
index 559c1f96372f7686f65fc3fe7ccc00bb92586c9a..3ebc03d1a3794aa755b68c597399da79ced1342a 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.
@@ -73,27 +73,25 @@ namespace
 /*! \brief Throw an error if any element in index exceeds a given number.
  *
  * \param[in] indices to be acessed
- * \param[in] largestOkayIndex to be accessed
+ * \param[in] numAtoms to be accessed
  * \param[in] indexUsagePurpose to be more explicit in the error message
  *
- * \throws RangeError if largestOkayIndex is larger than any element in indices
+ * \throws RangeError if any element in indices is larger than or equal numAtoms 
  *
  */
-void throwErrorIfIndexOutOfBounds(ArrayRef<const int> indices,
-                                  const int           largestOkayIndex,
-                                  const std::string&  indexUsagePurpose)
+void throwErrorIfIndexOutOfBounds(ArrayRef<const int> indices, const int numAtoms, const std::string& indexUsagePurpose)
 {
     // do nothing if index is empty
-    if (indices.ssize() == 0)
+    if (indices.empty())
     {
         return;
     }
     const int largestIndex = *std::max_element(indices.begin(), indices.end());
-    if (largestIndex < largestOkayIndex)
+    if (largestIndex >= numAtoms)
     {
-        GMX_THROW(RangeError("The provided structure file only contains "
-                             + std::to_string(largestOkayIndex) + " coordinates, but coordinate index "
-                             + std::to_string(largestIndex) + " was requested for " + indexUsagePurpose
+        GMX_THROW(RangeError("The provided structure file only contains " + std::to_string(numAtoms)
+                             + " coordinates, but coordinate index " + std::to_string(largestIndex + 1)
+                             + " was requested for " + indexUsagePurpose
                              + ". Make sure to update structure files "
                                "and index files if you store only a part of your system."));
     }