Skip to content

Commit

Permalink
Fix a potential segfault when using COORDS data sets (#900)
Browse files Browse the repository at this point in the history
* 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 <daniel.roe@nih.gov>
  • Loading branch information
drroe and Daniel R. Roe authored Apr 29, 2021
1 parent 17e4d3e commit 46b3c7e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/DataSet_Coords_CRD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Whenever a number that precedes <revision> 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
16 changes: 15 additions & 1 deletion test/Test_2DRMS/RunTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <<EOF
parm ../rGACC.full.parm7
for i=1;i<10;i++
trajin ../rGACC.full.nc
done
2drms crd1 :1-4&!@H= out rgacc.dat nosquare2d
EOF
RunCpptraj "2D RMSD test, read coords with velocity info"
DoTest rgacc.dat.save rgacc.dat

EndTest

exit 0
82 changes: 82 additions & 0 deletions test/Test_2DRMS/rgacc.dat.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# crd1
1.000 1.000 0.000
2.000 1.000 0.000
3.000 1.000 0.000
4.000 1.000 0.000
5.000 1.000 0.000
6.000 1.000 0.000
7.000 1.000 0.000
8.000 1.000 0.000
9.000 1.000 0.000
1.000 2.000 0.000
2.000 2.000 0.000
3.000 2.000 0.000
4.000 2.000 0.000
5.000 2.000 0.000
6.000 2.000 0.000
7.000 2.000 0.000
8.000 2.000 0.000
9.000 2.000 0.000
1.000 3.000 0.000
2.000 3.000 0.000
3.000 3.000 0.000
4.000 3.000 0.000
5.000 3.000 0.000
6.000 3.000 0.000
7.000 3.000 0.000
8.000 3.000 0.000
9.000 3.000 0.000
1.000 4.000 0.000
2.000 4.000 0.000
3.000 4.000 0.000
4.000 4.000 0.000
5.000 4.000 0.000
6.000 4.000 0.000
7.000 4.000 0.000
8.000 4.000 0.000
9.000 4.000 0.000
1.000 5.000 0.000
2.000 5.000 0.000
3.000 5.000 0.000
4.000 5.000 0.000
5.000 5.000 0.000
6.000 5.000 0.000
7.000 5.000 0.000
8.000 5.000 0.000
9.000 5.000 0.000
1.000 6.000 0.000
2.000 6.000 0.000
3.000 6.000 0.000
4.000 6.000 0.000
5.000 6.000 0.000
6.000 6.000 0.000
7.000 6.000 0.000
8.000 6.000 0.000
9.000 6.000 0.000
1.000 7.000 0.000
2.000 7.000 0.000
3.000 7.000 0.000
4.000 7.000 0.000
5.000 7.000 0.000
6.000 7.000 0.000
7.000 7.000 0.000
8.000 7.000 0.000
9.000 7.000 0.000
1.000 8.000 0.000
2.000 8.000 0.000
3.000 8.000 0.000
4.000 8.000 0.000
5.000 8.000 0.000
6.000 8.000 0.000
7.000 8.000 0.000
8.000 8.000 0.000
9.000 8.000 0.000
1.000 9.000 0.000
2.000 9.000 0.000
3.000 9.000 0.000
4.000 9.000 0.000
5.000 9.000 0.000
6.000 9.000 0.000
7.000 9.000 0.000
8.000 9.000 0.000
9.000 9.000 0.000

0 comments on commit 46b3c7e

Please sign in to comment.