AP_ESC_TELEM: prevent overrun, esc_index should be < to ESC_TELEM_MAX_ESCS

This commit is contained in:
Pierre Kancir 2021-08-11 00:12:06 +02:00 committed by Peter Barker
parent a0175441a0
commit 7739ddefd0
1 changed files with 3 additions and 3 deletions

View File

@ -91,7 +91,7 @@ bool AP_ESC_Telem::get_rpm(uint8_t esc_index, float& rpm) const
{
const volatile AP_ESC_Telem_Backend::RpmData& rpmdata = _rpm_data[esc_index];
if (esc_index > ESC_TELEM_MAX_ESCS || is_zero(rpmdata.update_rate_hz)) {
if (esc_index >= ESC_TELEM_MAX_ESCS || is_zero(rpmdata.update_rate_hz)) {
return false;
}
@ -288,7 +288,7 @@ void AP_ESC_Telem::update_telem_data(const uint8_t esc_index, const AP_ESC_Telem
// can only get slightly more up-to-date information that perhaps they were expecting or might
// read data that has just gone stale - both of these are safe and avoid the overhead of locking
if (esc_index > ESC_TELEM_MAX_ESCS) {
if (esc_index >= ESC_TELEM_MAX_ESCS) {
return;
}
@ -322,7 +322,7 @@ void AP_ESC_Telem::update_telem_data(const uint8_t esc_index, const AP_ESC_Telem
// this should be called by backends when new telemetry values are available
void AP_ESC_Telem::update_rpm(const uint8_t esc_index, const uint16_t new_rpm, const float error_rate)
{
if (esc_index > ESC_TELEM_MAX_ESCS) {
if (esc_index >= ESC_TELEM_MAX_ESCS) {
return;
}