Fix ptr overflow warning
Cast to ptrdiff_t, where negative ptr overflow is expected and add comments
Bug: webrtc:9166
Change-Id: Ib079791d67e4161b578cba15b67236822442ac08
Reviewed-on: https://webrtc-review.googlesource.com/70780
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22931}
diff --git a/common_audio/signal_processing/downsample_fast.c b/common_audio/signal_processing/downsample_fast.c
index 9a2ea05..80fdc58 100644
--- a/common_audio/signal_processing/downsample_fast.c
+++ b/common_audio/signal_processing/downsample_fast.c
@@ -42,8 +42,13 @@
out_s32 = 2048; // Round value, 0.5 in Q12.
for (j = 0; j < coefficients_length; j++) {
- rtc_MsanCheckInitialized(&data_in[i - j], sizeof(data_in[0]), 1);
- out_s32 += coefficients[j] * data_in[i - j]; // Q12.
+ // Negative overflow is permitted here, because this is
+ // auto-regressive filters, and the state for each batch run is
+ // stored in the "negative" positions of the output vector.
+ rtc_MsanCheckInitialized(&data_in[(ptrdiff_t) i - (ptrdiff_t) j],
+ sizeof(data_in[0]), 1);
+ // out_s32 is in Q12 domain.
+ out_s32 += coefficients[j] * data_in[(ptrdiff_t) i - (ptrdiff_t) j];
}
out_s32 >>= 12; // Q0.