AP_RangeFinder: fix potential out-of-bounds read

Issue found by Coverity
This commit is contained in:
Randy Mackay 2015-06-08 12:30:15 +09:00
parent 7613964ecb
commit d366c30358

View File

@ -311,7 +311,7 @@ void RangeFinder::detect_instance(uint8_t instance)
RangeFinder::RangeFinder_Status RangeFinder::status(uint8_t instance) const
{
// sanity check instance
if (instance > RANGEFINDER_MAX_INSTANCES) {
if (instance >= RANGEFINDER_MAX_INSTANCES) {
return RangeFinder_NotConnected;
}
@ -326,7 +326,7 @@ RangeFinder::RangeFinder_Status RangeFinder::status(uint8_t instance) const
bool RangeFinder::has_data(uint8_t instance) const
{
// sanity check instance
if (instance > RANGEFINDER_MAX_INSTANCES) {
if (instance >= RANGEFINDER_MAX_INSTANCES) {
return RangeFinder_NotConnected;
}
return ((state[instance].status != RangeFinder_NotConnected) && (state[instance].status != RangeFinder_NoData));