From 138ff7a316b7d8b48fea91256006232215a60bbe Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 2 Feb 2022 14:49:33 -0500 Subject: [PATCH] sensors: ensure that best accel/gyro is in bounds --- src/modules/sensors/voted_sensors_update.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/sensors/voted_sensors_update.cpp b/src/modules/sensors/voted_sensors_update.cpp index 963051aab6..934fb83c95 100644 --- a/src/modules/sensors/voted_sensors_update.cpp +++ b/src/modules/sensors/voted_sensors_update.cpp @@ -219,7 +219,9 @@ void VotedSensorsUpdate::imuPoll(struct sensor_combined_s &raw) } // write data for the best sensor to output variables - if ((accel_best_index >= 0) && (gyro_best_index >= 0)) { + if ((accel_best_index >= 0) && (accel_best_index < MAX_SENSOR_COUNT) + && (gyro_best_index >= 0) && (gyro_best_index < MAX_SENSOR_COUNT)) { + raw.timestamp = _last_sensor_data[gyro_best_index].timestamp; memcpy(&raw.accelerometer_m_s2, &_last_sensor_data[accel_best_index].accelerometer_m_s2, sizeof(raw.accelerometer_m_s2));