Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds correctness for AnalogIn_IIO #25747

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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