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}
This commit is contained in:
Artem Titov
2018-04-19 09:58:17 +02:00
committed by Commit Bot
parent 4db138e889
commit 13fb0ef801
3 changed files with 17 additions and 4 deletions

View File

@ -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.

View File

@ -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];

View File

@ -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