Skip to content

Commit 46b3c7e

Browse files
drroeDaniel R. Roe
andauthored
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 <[email protected]>
1 parent 17e4d3e commit 46b3c7e

File tree

4 files changed

+102
-6
lines changed

4 files changed

+102
-6
lines changed

src/DataSet_Coords_CRD.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ static inline void ArrayToFrame(int idx, Frame& fOut, CompactFrameArray const& f
133133
/** Get a frame from specified position in array. */
134134
void DataSet_Coords_CRD::GetFrame(int idx, Frame& fOut) {
135135
if (frames_.HasComponent(CoordinateInfo::POSITION)) frames_.GetToDblPtr(fOut.xAddress(), idx, CoordinateInfo::POSITION);
136-
if (frames_.HasComponent(CoordinateInfo::VELOCITY)) frames_.GetToDblPtr(fOut.vAddress(), idx, CoordinateInfo::VELOCITY);
137-
if (frames_.HasComponent(CoordinateInfo::FORCE)) frames_.GetToDblPtr(fOut.fAddress(), idx, CoordinateInfo::FORCE);
136+
if (frames_.HasComponent(CoordinateInfo::VELOCITY) && fOut.HasVelocity()) frames_.GetToDblPtr(fOut.vAddress(), idx, CoordinateInfo::VELOCITY);
137+
if (frames_.HasComponent(CoordinateInfo::FORCE) && fOut.HasForce()) frames_.GetToDblPtr(fOut.fAddress(), idx, CoordinateInfo::FORCE);
138138
ArrayToFrame(idx, fOut, frames_);
139139
}
140140

141141
/** Get selected atoms from a frame from specified position in array. */
142142
void DataSet_Coords_CRD::GetFrame(int idx, Frame& fOut, AtomMask const& mask) {
143143
if (frames_.HasComponent(CoordinateInfo::POSITION)) frames_.GetToMaskDblPtr(fOut.xAddress(), mask.Selected(), idx, CoordinateInfo::POSITION);
144-
if (frames_.HasComponent(CoordinateInfo::VELOCITY)) frames_.GetToMaskDblPtr(fOut.vAddress(), mask.Selected(), idx, CoordinateInfo::VELOCITY);
145-
if (frames_.HasComponent(CoordinateInfo::FORCE)) frames_.GetToMaskDblPtr(fOut.fAddress(), mask.Selected(), idx, CoordinateInfo::FORCE);
144+
if (frames_.HasComponent(CoordinateInfo::VELOCITY) && fOut.HasVelocity()) frames_.GetToMaskDblPtr(fOut.vAddress(), mask.Selected(), idx, CoordinateInfo::VELOCITY);
145+
if (frames_.HasComponent(CoordinateInfo::FORCE) && fOut.HasForce()) frames_.GetToMaskDblPtr(fOut.fAddress(), mask.Selected(), idx, CoordinateInfo::FORCE);
146146
ArrayToFrame(idx, fOut, frames_);
147147
}
148148

src/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Whenever a number that precedes <revision> is incremented, all subsequent
1313
* numbers should be reset to 0.
1414
*/
15-
#define CPPTRAJ_INTERNAL_VERSION "V5.3.1"
15+
#define CPPTRAJ_INTERNAL_VERSION "V5.3.2"
1616
/// PYTRAJ relies on this
1717
#define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION
1818
#endif

test/Test_2DRMS/RunTest.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
. ../MasterTest.sh
44

55
# Clean
6-
CleanFiles rms.in rmsd1.dat rmsd2.dat ref.nc rmsd.mass.dat dme.dat trp.dat nofit.dat
6+
CleanFiles rms.in rmsd1.dat rmsd2.dat ref.nc rmsd.mass.dat dme.dat trp.dat \
7+
nofit.dat rgacc.dat
78

89
TESTNAME='2D RMSD tests'
910
Requires netcdf maxthreads 10
@@ -73,6 +74,19 @@ EOF
7374
RunCpptraj "2D RMSD test, no fitting."
7475
DoTest nofit.dat.save nofit.dat
7576

77+
# Test 7 - coords with velocities
78+
TOP=''
79+
CRD=''
80+
cat > rms.in <<EOF
81+
parm ../rGACC.full.parm7
82+
for i=1;i<10;i++
83+
trajin ../rGACC.full.nc
84+
done
85+
2drms crd1 :1-4&!@H= out rgacc.dat nosquare2d
86+
EOF
87+
RunCpptraj "2D RMSD test, read coords with velocity info"
88+
DoTest rgacc.dat.save rgacc.dat
89+
7690
EndTest
7791

7892
exit 0

test/Test_2DRMS/rgacc.dat.save

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# crd1
2+
1.000 1.000 0.000
3+
2.000 1.000 0.000
4+
3.000 1.000 0.000
5+
4.000 1.000 0.000
6+
5.000 1.000 0.000
7+
6.000 1.000 0.000
8+
7.000 1.000 0.000
9+
8.000 1.000 0.000
10+
9.000 1.000 0.000
11+
1.000 2.000 0.000
12+
2.000 2.000 0.000
13+
3.000 2.000 0.000
14+
4.000 2.000 0.000
15+
5.000 2.000 0.000
16+
6.000 2.000 0.000
17+
7.000 2.000 0.000
18+
8.000 2.000 0.000
19+
9.000 2.000 0.000
20+
1.000 3.000 0.000
21+
2.000 3.000 0.000
22+
3.000 3.000 0.000
23+
4.000 3.000 0.000
24+
5.000 3.000 0.000
25+
6.000 3.000 0.000
26+
7.000 3.000 0.000
27+
8.000 3.000 0.000
28+
9.000 3.000 0.000
29+
1.000 4.000 0.000
30+
2.000 4.000 0.000
31+
3.000 4.000 0.000
32+
4.000 4.000 0.000
33+
5.000 4.000 0.000
34+
6.000 4.000 0.000
35+
7.000 4.000 0.000
36+
8.000 4.000 0.000
37+
9.000 4.000 0.000
38+
1.000 5.000 0.000
39+
2.000 5.000 0.000
40+
3.000 5.000 0.000
41+
4.000 5.000 0.000
42+
5.000 5.000 0.000
43+
6.000 5.000 0.000
44+
7.000 5.000 0.000
45+
8.000 5.000 0.000
46+
9.000 5.000 0.000
47+
1.000 6.000 0.000
48+
2.000 6.000 0.000
49+
3.000 6.000 0.000
50+
4.000 6.000 0.000
51+
5.000 6.000 0.000
52+
6.000 6.000 0.000
53+
7.000 6.000 0.000
54+
8.000 6.000 0.000
55+
9.000 6.000 0.000
56+
1.000 7.000 0.000
57+
2.000 7.000 0.000
58+
3.000 7.000 0.000
59+
4.000 7.000 0.000
60+
5.000 7.000 0.000
61+
6.000 7.000 0.000
62+
7.000 7.000 0.000
63+
8.000 7.000 0.000
64+
9.000 7.000 0.000
65+
1.000 8.000 0.000
66+
2.000 8.000 0.000
67+
3.000 8.000 0.000
68+
4.000 8.000 0.000
69+
5.000 8.000 0.000
70+
6.000 8.000 0.000
71+
7.000 8.000 0.000
72+
8.000 8.000 0.000
73+
9.000 8.000 0.000
74+
1.000 9.000 0.000
75+
2.000 9.000 0.000
76+
3.000 9.000 0.000
77+
4.000 9.000 0.000
78+
5.000 9.000 0.000
79+
6.000 9.000 0.000
80+
7.000 9.000 0.000
81+
8.000 9.000 0.000
82+
9.000 9.000 0.000

0 commit comments

Comments
 (0)