diff --git a/common_audio/signal_processing/filter_ar.c b/common_audio/signal_processing/filter_ar.c index 49d5d61960..2471cd1117 100644 --- a/common_audio/signal_processing/filter_ar.c +++ b/common_audio/signal_processing/filter_ar.c @@ -17,6 +17,8 @@ #include "common_audio/signal_processing/include/signal_processing_library.h" +#include "rtc_base/checks.h" + size_t WebRtcSpl_FilterAR(const int16_t* a, size_t a_length, const int16_t* x, @@ -40,8 +42,10 @@ size_t WebRtcSpl_FilterAR(const int16_t* a, { // Calculate filtered[i] and filtered_low[i] const int16_t* a_ptr = &a[1]; - int16_t* filtered_ptr = &filtered[i - 1]; - int16_t* filtered_low_ptr = &filtered_low[i - 1]; + // The index can become negative, but the arrays will never be indexed + // with it when negative. Nevertheless, the index cannot be a size_t + // because of this. + int filtered_ix = (int)i - 1; int16_t* state_ptr = &state[state_length - 1]; int16_t* state_low_ptr = &state_low[state_length - 1]; @@ -51,8 +55,10 @@ size_t WebRtcSpl_FilterAR(const int16_t* a, stop = (i < a_length) ? i + 1 : a_length; for (j = 1; j < stop; j++) { - o -= *a_ptr * *filtered_ptr--; - oLOW -= *a_ptr++ * *filtered_low_ptr--; + RTC_DCHECK_GE(filtered_ix, 0); + o -= *a_ptr * filtered[filtered_ix]; + oLOW -= *a_ptr++ * filtered_low[filtered_ix]; + --filtered_ix; } for (j = i + 1; j < a_length; j++) {