Fix out of bound vector access in vsites
authorRoland Schulz <roland@rschulz.eu>
Wed, 22 Sep 2021 04:49:39 +0000 (21:49 -0700)
committerRoland Schulz <roland.schulz@intel.com>
Wed, 22 Sep 2021 17:45:10 +0000 (17:45 +0000)
operator[] is invalid for one past the last element. Using
the pointer to it as end-pointer is fine.

Found by Microsoft STL debug iterator.

src/programs/mdrun/tests/virtualsites.cpp

index c6b6009453eb513061ca7ff2ea0f36bf02b60592..8ce0c33d856f4e566ee60dff791d8974684578ae 100644 (file)
@@ -330,8 +330,8 @@ public:
                     virtualSites.emplace_back(VirtualSite{
                             vsiteType,
                             virtualSiteIdx,
-                            { &interactionList.iatoms[i + 2],
-                              &interactionList.iatoms[i + 2 + numConstructingAtoms] },
+                            { interactionList.iatoms.data() + i + 2,
+                              interactionList.iatoms.data() + i + 2 + numConstructingAtoms },
                             { localTopology.idef.iparams[parameterIdx].generic.buf,
                               localTopology.idef.iparams[parameterIdx].generic.buf + MAXFORCEPARAM } });
                     i += defaultIncrement;