Skip to content

Commit

Permalink
SITL: fix array-bounds warning in tsys01 sim
Browse files Browse the repository at this point in the history
... if the driver ever asked for prom0 then we would do Very Bad Things here.

File:	build/sitl/../../libraries/SITL/SIM_Temperature_TSYS01.cpp
Warning:	line 38, column 13
Assigned value is garbage or undefined
  • Loading branch information
peterbarker committed Jan 29, 2025
1 parent 99a5018 commit 21e5734
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libraries/SITL/SIM_Temperature_TSYS01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

constexpr const int32_t SITL::TSYS01::_k[5];
constexpr const int32_t SITL::TSYS01::_k[6];

int SITL::TSYS01::rdwr(I2C::i2c_rdwr_ioctl_data *&data)
{
Expand Down Expand Up @@ -34,7 +34,7 @@ int SITL::TSYS01::rdwr(I2C::i2c_rdwr_ioctl_data *&data)
if (data->msgs[1].len != 2) {
AP_HAL::panic("Unexpected prom read length");
}
uint8_t offs = 5-((uint8_t(command) - uint8_t(Command::READ_PROM0))/2);
uint8_t offs = ARRAY_SIZE(_k)-((uint8_t(command) - uint8_t(Command::READ_PROM0))/2);
const uint16_t k = _k[offs];
data->msgs[1].buf[0] = k >> 8;
data->msgs[1].buf[1] = k & 0xFF;
Expand Down
3 changes: 2 additions & 1 deletion libraries/SITL/SIM_Temperature_TSYS01.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class TSYS01 : public I2CDevice
READ_ADC = 0x00,
};

static constexpr int32_t _k[] { 40781, 32791, 36016, 24926, 28446 };
// _k[0] is unused
static constexpr int32_t _k[] { 0, 40781, 32791, 36016, 24926, 28446 };
};

} // namespace SITL
Expand Down

0 comments on commit 21e5734

Please sign in to comment.