Clamp lis2dw FIFO count to buffer size

The FIFO sample-count field can report up to 63, but readings[] only holds
32. Clamp the count so a glitched or overrun value can't overflow the buffer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Konrad Rieck
2026-08-03 18:06:55 +02:00
parent b2589bebcd
commit d7f8375def

View File

@ -285,6 +285,12 @@ bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data, uint32_t timeout) {
fifo_data->count = temp & LIS2DW_FIFO_SAMPLE_COUNT;
/* The count field can report up to 63, but readings[] only holds 32.
Clamp so a glitched or overrun count can't overflow the buffer. */
if (fifo_data->count > 32) {
fifo_data->count = 32;
}
rtc_counter_t timeout_counter = watch_rtc_get_counter() + timeout;
for(int i = 0; i < fifo_data->count; i++) {
if (watch_rtc_get_counter() > timeout_counter) {