From abd5bffda5322204caaca715d4aa897761d27c79 Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Mon, 28 May 2018 13:12:26 -0700 Subject: [PATCH] AP_Airspeed: Clean up some comments, prevent a potential out of range access --- libraries/AP_Airspeed/AP_Airspeed.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/AP_Airspeed/AP_Airspeed.h b/libraries/AP_Airspeed/AP_Airspeed.h index 02fbdf588f..e63c939bd4 100644 --- a/libraries/AP_Airspeed/AP_Airspeed.h +++ b/libraries/AP_Airspeed/AP_Airspeed.h @@ -83,7 +83,10 @@ public: // return true if airspeed is enabled bool enabled(uint8_t i) const { - return param[i].type.get() != TYPE_NONE; + if (i < AIRSPEED_MAX_SENSORS) { + return param[i].type.get() != TYPE_NONE; + } + return false; } bool enabled(void) const { return enabled(primary); } @@ -92,8 +95,7 @@ public: state[primary].airspeed = airspeed; } - // return the differential pressure in Pascal for the last - // airspeed reading. Used by the calibration code + // return the differential pressure in Pascal for the last airspeed reading float get_differential_pressure(uint8_t i) const { return state[i].last_pressure; } @@ -215,6 +217,8 @@ private: uint8_t primary; void read(uint8_t i); + // return the differential pressure in Pascal for the last airspeed reading for the requested instance + // returns 0 if the sensor is not enabled float get_pressure(uint8_t i); void update_calibration(uint8_t i, float raw_pressure); void update_calibration(uint8_t i, const Vector3f &vground, int16_t max_airspeed_allowed_during_cal);