From 9812fc9574600d47019fc64ee50b4113343aec91 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 8 Jan 2018 15:33:08 +1100 Subject: [PATCH] HAL_Chibios: prevent creation of i2c devices on invalid bus --- libraries/AP_HAL_ChibiOS/I2CDevice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/I2CDevice.cpp b/libraries/AP_HAL_ChibiOS/I2CDevice.cpp index f91d617fb2..69e4dbe4d9 100644 --- a/libraries/AP_HAL_ChibiOS/I2CDevice.cpp +++ b/libraries/AP_HAL_ChibiOS/I2CDevice.cpp @@ -190,6 +190,9 @@ bool I2CDevice::adjust_periodic_callback(AP_HAL::Device::PeriodicHandle h, uint3 AP_HAL::OwnPtr I2CDeviceManager::get_device(uint8_t bus, uint8_t address) { + if (bus >= ARRAY_SIZE(I2CD)) { + return AP_HAL::OwnPtr(nullptr); + } auto dev = AP_HAL::OwnPtr(new I2CDevice(bus, address)); return dev; }