Skip to content

Commit 3b65760

Browse files
committed
AP_Baro: correct duplication check for i2c baro devices
we're indexing into the sensors array, so we should only iterate up to the number of sensors we have could be a problem if there are DroneCAN backends involved as that can cause a mismatch between _num_sensors and _num_drivers
1 parent 1cde2fb commit 3b65760

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libraries/AP_Baro/AP_Baro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ bool AP_Baro::_add_backend(AP_Baro_Backend *backend)
504504
*/
505505
bool AP_Baro::_have_i2c_driver(uint8_t bus, uint8_t address) const
506506
{
507-
for (int i=0; i<_num_drivers; ++i) {
507+
for (int i=0; i<_num_sensors; ++i) {
508508
if (AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_I2C, bus, address, 0) ==
509509
AP_HAL::Device::change_bus_id(uint32_t(sensors[i].bus_id.get()), 0)) {
510510
// device already has been defined.

0 commit comments

Comments
 (0)