From 781412022ff202a7351c9959196d5922eece33f4 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 22 Oct 2019 18:45:33 -0400 Subject: [PATCH] Fix ESC_SENSOR blackbox debug overflow for more than 4 motors Would cause an array index overflow if more than 4 motors and debug_mode ESC_SENSOR_RPM or ESC_SENSOR_TMP were used. --- src/main/sensors/esc_sensor.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c index 2fd83e513..2f7c0063b 100644 --- a/src/main/sensors/esc_sensor.c +++ b/src/main/sensors/esc_sensor.c @@ -270,8 +270,10 @@ static uint8_t decodeEscFrame(void) frameStatus = ESC_SENSOR_FRAME_COMPLETE; - DEBUG_SET(DEBUG_ESC_SENSOR_RPM, escSensorMotor, calcEscRpm(escSensorData[escSensorMotor].rpm) / 10); // output actual rpm/10 to fit in 16bit signed. - DEBUG_SET(DEBUG_ESC_SENSOR_TMP, escSensorMotor, escSensorData[escSensorMotor].temperature); + if (escSensorMotor < 4) { + DEBUG_SET(DEBUG_ESC_SENSOR_RPM, escSensorMotor, calcEscRpm(escSensorData[escSensorMotor].rpm) / 10); // output actual rpm/10 to fit in 16bit signed. + DEBUG_SET(DEBUG_ESC_SENSOR_TMP, escSensorMotor, escSensorData[escSensorMotor].temperature); + } } else { frameStatus = ESC_SENSOR_FRAME_FAILED; }