aboutsummaryrefslogtreecommitdiff
path: root/common_audio
diff options
context:
space:
mode:
authorArtem Titov <titovartem@webrtc.org>2018-04-19 09:58:17 +0200
committerCommit Bot <commit-bot@chromium.org>2018-04-19 08:58:18 +0000
commit13fb0ef801385f0e2191d614c42f74581e3934da (patch)
tree4ecbfb0ccba77d56232057a32ef6b27c1c0ba7fe /common_audio
parent4db138e889ba3508329783c34462a8b82bde1070 (diff)
downloadwebrtc-13fb0ef801385f0e2191d614c42f74581e3934da.tar.gz
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}
Diffstat (limited to 'common_audio')
-rw-r--r--common_audio/signal_processing/downsample_fast.c9
-rw-r--r--common_audio/signal_processing/filter_ar_fast_q12.c7
-rw-r--r--common_audio/signal_processing/filter_ma_fast_q12.c5
3 files changed, 17 insertions, 4 deletions
diff --git a/common_audio/signal_processing/downsample_fast.c b/common_audio/signal_processing/downsample_fast.c
index 9a2ea053da..80fdc58a49 100644
--- a/common_audio/signal_processing/downsample_fast.c
+++ b/common_audio/signal_processing/downsample_fast.c
@@ -42,8 +42,13 @@ int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
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 df9e51889a..8b8bdb1af5 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 @@ void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
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 9596ef1922..329d47e14f 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 @@ void WebRtcSpl_FilterMAFastQ12(const int16_t* in_ptr,
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