From 703020be12f5b572880801906a50b3ffabecc333 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Thu, 19 Jan 2023 20:43:27 +0000 Subject: [PATCH] AP_HAL: ensure the DSP tracked peaks do not overflow the buffer --- libraries/AP_HAL/DSP.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/AP_HAL/DSP.cpp b/libraries/AP_HAL/DSP.cpp index 795d2df335..bdc59e68bb 100644 --- a/libraries/AP_HAL/DSP.cpp +++ b/libraries/AP_HAL/DSP.cpp @@ -358,6 +358,8 @@ uint16_t DSP::fft_stop_average(FFTWindowState* fft, uint16_t start_bin, uint16_t scratch_space, peaks, MAX_TRACKED_PEAKS, 0.0f, -1.0f, smoothwidth, 2); hal.util->free_type(scratch_space, sizeof(float) * fft->_num_stored_freqs, DSP_MEM_REGION); + numpeaks = MIN(numpeaks, uint16_t(MAX_TRACKED_PEAKS)); + // now try and find the lowest harmonic for (uint16_t i = 0; i < numpeaks; i++) { const uint16_t bin = peaks[i] + start_bin;