Skip to content

Commit a009df6

Browse files
[Log] Check size of vector before writing.
1 parent 54b3509 commit a009df6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/log.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,35 @@ void Log::record(DataToLog &aDataToLog) {
9090
StoredData_.controls[JointID + lref_] = aDataToLog.controls[JointID];
9191
}
9292
for (unsigned int axis = 0; axis < 3; axis++) {
93-
StoredData_.accelerometer[lrefts_ * 3 + axis] =
93+
if (StoredData_.accelerometer.size() >= lrefts_ * 3 + 3)
94+
StoredData_.accelerometer[lrefts_ * 3 + axis] =
9495
aDataToLog.accelerometer[axis];
95-
StoredData_.gyrometer[lrefts_ * 3 + axis] = aDataToLog.gyrometer[axis];
96+
}
97+
for (unsigned int axis = 0; axis < 3; axis++) {
98+
if (StoredData_.gyrometer.size() >= lrefts_ * 3 + 3)
99+
StoredData_.gyrometer[lrefts_ * 3 + axis] = aDataToLog.gyrometer[axis];
96100
}
97101
std::size_t width_pad = 6 * profileLog_.nbForceSensors;
98102

99103
for (unsigned int fsID = 0; fsID < profileLog_.nbForceSensors; fsID++) {
100104
for (unsigned int axis = 0; axis < 6; axis++) {
101-
StoredData_.force_sensors[lrefts_ * width_pad + fsID * 6 + axis] =
105+
if (StoredData_.force_sensors.size() > lrefts_ * width_pad +
106+
(profileLog_.nbForceSensors - 1) * 6 + 5)
107+
StoredData_.force_sensors[lrefts_ * width_pad + fsID * 6 + axis] =
102108
aDataToLog.force_sensors[fsID * 6 + axis];
103109
}
104110
}
105111

106112
struct timeval current;
107113
gettimeofday(&current, 0);
108114

109-
StoredData_.timestamp[lrefts_] =
115+
if (StoredData_.timestamp.size() > lrefts_) {
116+
StoredData_.timestamp[lrefts_] =
110117
((double)current.tv_sec + 0.000001 * (double)current.tv_usec) -
111118
timeorigin_;
112119

113-
StoredData_.duration[lrefts_] = time_stop_it_ - time_start_it_;
114-
120+
StoredData_.duration[lrefts_] = time_stop_it_ - time_start_it_;
121+
}
115122
lref_ += profileLog_.nbDofs;
116123
lrefts_++;
117124
if (lref_ >= profileLog_.nbDofs * profileLog_.length) {

0 commit comments

Comments
 (0)