Fix rare UB / assertion failure in MdlibUnitTest
authorAndrey Alekseenko <al42and@gmail.com>
Tue, 21 Sep 2021 12:21:15 +0000 (15:21 +0300)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 21 Sep 2021 12:29:18 +0000 (15:29 +0300)
In LeapFrogHostTestRunner::integrate, we were checking whether
testData->mdAtoms_.ptype is null, but we were not initializing this
field.

This was leading to occasional assertion failure in
ArrayRef constructor from this pointer when begin+size was overflowing,
which caused end < begin.

Only unit tests were affected.

src/gromacs/mdlib/tests/leapfrogtestdata.cpp

index 9d1f7780be68a05a173877aad803ecd15881f374..3f66855450e8cdec66b8e57c54b1db109c8429ac 100644 (file)
@@ -170,6 +170,7 @@ LeapFrogTestData::LeapFrogTestData(int        numAtoms,
     mdAtoms_.haveVsites               = false;
     mdAtoms_.havePartiallyFrozenAtoms = false;
     mdAtoms_.cFREEZE                  = nullptr;
+    mdAtoms_.ptype                    = nullptr;
 
     update_ = std::make_unique<Update>(inputRecord_, nullptr);
     update_->updateAfterPartition(numAtoms,