Skip to content

Commit

Permalink
Bounds correctness for AnalogIn_IIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy Protas committed Dec 10, 2023
1 parent 273e079 commit 74f39c8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libraries/AP_HAL_Linux/AnalogIn_IIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ AnalogSource_IIO::AnalogSource_IIO(int16_t pin, float initial_value, float volta

void AnalogSource_IIO::init_pins(void)
{
static_assert(ARRAY_SIZE(AnalogSource_IIO::analog_sources) == ARRAY_SIZE(fd_analog_sources), "AnalogIn_IIO channels count mismatch");

char buf[100];
for (unsigned int i = 0; i < ARRAY_SIZE(AnalogSource_IIO::analog_sources); i++) {
// Construct the path by appending strings
Expand All @@ -44,7 +46,11 @@ void AnalogSource_IIO::init_pins(void)
*/
void AnalogSource_IIO::select_pin(void)
{
_pin_fd = fd_analog_sources[_pin];
if (0 <= _pin && (size_t)_pin < ARRAY_SIZE(fd_analog_sources)) {
_pin_fd = fd_analog_sources[_pin];
} else {
_pin_fd = -1;
}
}

float AnalogSource_IIO::read_average()
Expand Down

0 comments on commit 74f39c8

Please sign in to comment.