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.
diff --git a/common_audio/signal_processing/filter_ar_fast_q12.c b/common_audio/signal_processing/filter_ar_fast_q12.c
index df9e518..8b8bdb1 100644
--- a/common_audio/signal_processing/filter_ar_fast_q12.c
+++ b/common_audio/signal_processing/filter_ar_fast_q12.c
@@ -8,6 +8,8 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
+#include "stddef.h"
+
 #include "rtc_base/checks.h"
 #include "common_audio/signal_processing/include/signal_processing_library.h"
 
@@ -29,7 +31,10 @@
     int64_t sum = 0;
 
     for (j = coefficients_length - 1; j > 0; j--) {
-      sum += coefficients[j] * data_out[i - j];
+      // 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.
+      sum += coefficients[j] * data_out[(ptrdiff_t) i - (ptrdiff_t) j];
     }
 
     output = coefficients[0] * data_in[i];
diff --git a/common_audio/signal_processing/filter_ma_fast_q12.c b/common_audio/signal_processing/filter_ma_fast_q12.c
index 9596ef1..329d47e 100644
--- a/common_audio/signal_processing/filter_ma_fast_q12.c
+++ b/common_audio/signal_processing/filter_ma_fast_q12.c
@@ -37,7 +37,10 @@
 
         for (j = 0; j < B_length; j++)
         {
-          o += B[j] * in_ptr[i - j];
+          // 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.
+          o += B[j] * in_ptr[(ptrdiff_t) i - (ptrdiff_t) j];
         }
 
         // If output is higher than 32768, saturate it. Same with negative side