13
0

Potential fix for a race.

Do proper bounds checks and force the use of operator[] () const
This commit is contained in:
Johannes Mueller 2019-05-25 21:55:45 +02:00
parent 16d6791566
commit af875e0edc
2 changed files with 14 additions and 9 deletions

View File

@ -601,23 +601,28 @@ void ContourDesignControlProtocol::jump_backward (JumpDistance dist)
}
void
ContourDesignControlProtocol::set_shuttle_speed (int index, double speed)
ContourDesignControlProtocol::set_shuttle_speed (unsigned int index, double speed)
{
/* called from GUI thread */
// XXX this may race with ContourDesignControlProtocol::shuttle_event()
// TODO: add bounds check
if (index >= _shuttle_speeds.size()) {
return;
}
_shuttle_speeds[index] = speed;
}
void
ContourDesignControlProtocol::shuttle_event(int position)
ContourDesignControlProtocol::shuttle_event (int position)
{
DEBUG_TRACE (DEBUG::ContourDesignControl, string_compose ("shuttle event %1\n", position));
if (abs(position) > num_shuttle_speeds) {
DEBUG_TRACE (DEBUG::ContourDesignControl, "received invalid shuttle position... ignoring.\n");
return;
}
if (position != 0) {
if (_shuttle_was_zero) {
_was_rolling_before_shuttle = session->transport_rolling ();
}
double speed = position > 0 ? _shuttle_speeds[position-1] : -_shuttle_speeds[-position-1];
const vector<double>& spds = _shuttle_speeds;
const double speed = position > 0 ? spds[position-1] : -spds[-position-1];
set_transport_speed (speed);
_shuttle_was_zero = false;
} else {

View File

@ -114,8 +114,8 @@ public:
JumpDistance jog_distance () const { return _jog_distance; }
void set_jog_distance (JumpDistance jd) { _jog_distance = jd; }
void set_shuttle_speed (int index, double speed);
double shuttle_speed (int index) const {
void set_shuttle_speed (unsigned int index, double speed);
double shuttle_speed (unsigned int index) const {
return _shuttle_speeds[index];
}