From 46b3c7e81d9781665edbaf04c85fe49e80930e7f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 29 Apr 2021 12:47:51 -0400 Subject: [PATCH] Fix a potential segfault when using COORDS data sets (#900) * Do not try to set force and velocity if not allocated in the output frame. * Add 2drms test on coords with velocity info. Will be all zero but would catch the previously fixed segfault * Revision bump for COORDS potential segfault fix Co-authored-by: Daniel R. Roe --- src/DataSet_Coords_CRD.cpp | 8 ++-- src/Version.h | 2 +- test/Test_2DRMS/RunTest.sh | 16 ++++++- test/Test_2DRMS/rgacc.dat.save | 82 ++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 test/Test_2DRMS/rgacc.dat.save diff --git a/src/DataSet_Coords_CRD.cpp b/src/DataSet_Coords_CRD.cpp index 7a69f97872..ecafc785a6 100644 --- a/src/DataSet_Coords_CRD.cpp +++ b/src/DataSet_Coords_CRD.cpp @@ -133,16 +133,16 @@ static inline void ArrayToFrame(int idx, Frame& fOut, CompactFrameArray const& f /** Get a frame from specified position in array. */ void DataSet_Coords_CRD::GetFrame(int idx, Frame& fOut) { if (frames_.HasComponent(CoordinateInfo::POSITION)) frames_.GetToDblPtr(fOut.xAddress(), idx, CoordinateInfo::POSITION); - if (frames_.HasComponent(CoordinateInfo::VELOCITY)) frames_.GetToDblPtr(fOut.vAddress(), idx, CoordinateInfo::VELOCITY); - if (frames_.HasComponent(CoordinateInfo::FORCE)) frames_.GetToDblPtr(fOut.fAddress(), idx, CoordinateInfo::FORCE); + if (frames_.HasComponent(CoordinateInfo::VELOCITY) && fOut.HasVelocity()) frames_.GetToDblPtr(fOut.vAddress(), idx, CoordinateInfo::VELOCITY); + if (frames_.HasComponent(CoordinateInfo::FORCE) && fOut.HasForce()) frames_.GetToDblPtr(fOut.fAddress(), idx, CoordinateInfo::FORCE); ArrayToFrame(idx, fOut, frames_); } /** Get selected atoms from a frame from specified position in array. */ void DataSet_Coords_CRD::GetFrame(int idx, Frame& fOut, AtomMask const& mask) { if (frames_.HasComponent(CoordinateInfo::POSITION)) frames_.GetToMaskDblPtr(fOut.xAddress(), mask.Selected(), idx, CoordinateInfo::POSITION); - if (frames_.HasComponent(CoordinateInfo::VELOCITY)) frames_.GetToMaskDblPtr(fOut.vAddress(), mask.Selected(), idx, CoordinateInfo::VELOCITY); - if (frames_.HasComponent(CoordinateInfo::FORCE)) frames_.GetToMaskDblPtr(fOut.fAddress(), mask.Selected(), idx, CoordinateInfo::FORCE); + if (frames_.HasComponent(CoordinateInfo::VELOCITY) && fOut.HasVelocity()) frames_.GetToMaskDblPtr(fOut.vAddress(), mask.Selected(), idx, CoordinateInfo::VELOCITY); + if (frames_.HasComponent(CoordinateInfo::FORCE) && fOut.HasForce()) frames_.GetToMaskDblPtr(fOut.fAddress(), mask.Selected(), idx, CoordinateInfo::FORCE); ArrayToFrame(idx, fOut, frames_); } diff --git a/src/Version.h b/src/Version.h index bd2c7716a0..37ebe70960 100644 --- a/src/Version.h +++ b/src/Version.h @@ -12,7 +12,7 @@ * Whenever a number that precedes is incremented, all subsequent * numbers should be reset to 0. */ -#define CPPTRAJ_INTERNAL_VERSION "V5.3.1" +#define CPPTRAJ_INTERNAL_VERSION "V5.3.2" /// PYTRAJ relies on this #define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION #endif diff --git a/test/Test_2DRMS/RunTest.sh b/test/Test_2DRMS/RunTest.sh index 4011f1f4f2..b1744de3b7 100755 --- a/test/Test_2DRMS/RunTest.sh +++ b/test/Test_2DRMS/RunTest.sh @@ -3,7 +3,8 @@ . ../MasterTest.sh # Clean -CleanFiles rms.in rmsd1.dat rmsd2.dat ref.nc rmsd.mass.dat dme.dat trp.dat nofit.dat +CleanFiles rms.in rmsd1.dat rmsd2.dat ref.nc rmsd.mass.dat dme.dat trp.dat \ + nofit.dat rgacc.dat TESTNAME='2D RMSD tests' Requires netcdf maxthreads 10 @@ -73,6 +74,19 @@ EOF RunCpptraj "2D RMSD test, no fitting." DoTest nofit.dat.save nofit.dat +# Test 7 - coords with velocities +TOP='' +CRD='' +cat > rms.in <