iSAC entropy coder: Avoid signed integer overflow

By doing an unsigned instead of a signed addition, we get the exact
same machine code (in non-UBSan builds), but no longer trigger
undefined behavior since unsigned overflow is defined behavior.

BUG=webrtc:5485

Review URL: https://codereview.webrtc.org/1734883003

Cr-Commit-Position: refs/heads/master@{#11776}
This commit is contained in:
kwiberg 2016-02-26 02:52:12 -08:00 committed by Commit bot
parent db25d2e8c5
commit 806706875d
3 changed files with 8 additions and 11 deletions

View File

@ -15,10 +15,7 @@ src:*/third_party/yasm/*
src:*/usr/*
#############################################################################
# iSAC exhibits a few problems (entropy coding and a unit test).
# https://bugs.chromium.org/p/webrtc/issues/detail?id=5513
src:*/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c
src:*/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c
fun:*FilterBanksTest*CalculateResidualEnergyTester*
#############################################################################
@ -35,4 +32,4 @@ src:*/webrtc/common_audio/signal_processing/resample_by_2_internal.c
fun:*WebRtcSpl_AddSatW32*
fun:*WebRtcSpl_SubSatW32*
fun:*WebRtcSpl_DivW32HiLow*
fun:*GmmProbability*
fun:*GmmProbability*

View File

@ -392,13 +392,13 @@ static void GenerateDitherQ7(int16_t *bufQ7,
seed = WEBRTC_SPL_UMUL(seed, 196314165) + 907633515;
/* fixed-point dither sample between -64 and 64 (Q7) */
dither1_Q7 = (int16_t)(((int32_t)seed + 16777216) >> 25);
dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
/* new random unsigned int32_t */
seed = WEBRTC_SPL_UMUL(seed, 196314165) + 907633515;
/* fixed-point dither sample between -64 and 64 */
dither2_Q7 = (int16_t)((seed + 16777216) >> 25);
dither2_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
shft = (int16_t)(WEBRTC_SPL_RSHIFT_U32(seed, 25) & 15);
if (shft < 5)
@ -432,7 +432,7 @@ static void GenerateDitherQ7(int16_t *bufQ7,
seed = WEBRTC_SPL_UMUL(seed, 196314165) + 907633515;
/* fixed-point dither sample between -64 and 64 */
dither1_Q7 = (int16_t)(((int32_t)seed + 16777216) >> 25);
dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
/* dither sample is placed in either even or odd index */
shft = (int16_t)(WEBRTC_SPL_RSHIFT_U32(seed, 25) & 1); /* either 0 or 1 */

View File

@ -182,13 +182,13 @@ static void GenerateDitherQ7Lb(int16_t* bufQ7, uint32_t seed,
/* Fixed-point dither sample between -64 and 64 (Q7). */
/* dither = seed * 128 / 4294967295 */
dither1_Q7 = (int16_t)(((int)seed + 16777216) >> 25);
dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
/* New random unsigned int. */
seed = (seed * 196314165) + 907633515;
/* Fixed-point dither sample between -64 and 64. */
dither2_Q7 = (int16_t)(((int)seed + 16777216) >> 25);
dither2_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
shft = (seed >> 25) & 15;
if (shft < 5) {
@ -214,7 +214,7 @@ static void GenerateDitherQ7Lb(int16_t* bufQ7, uint32_t seed,
seed = (seed * 196314165) + 907633515;
/* Fixed-point dither sample between -64 and 64. */
dither1_Q7 = (int16_t)(((int)seed + 16777216) >> 25);
dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
/* Dither sample is placed in either even or odd index. */
shft = (seed >> 25) & 1; /* Either 0 or 1 */
@ -254,7 +254,7 @@ static void GenerateDitherQ7LbUB(
/* Fixed-point dither sample between -64 and 64 (Q7). */
/* bufQ7 = seed * 128 / 4294967295 */
bufQ7[k] = (int16_t)(((int)seed + 16777216) >> 25);
bufQ7[k] = (int16_t)(((int32_t)(seed + 16777216)) >> 25);
/* Scale by 0.35. */
bufQ7[k] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(bufQ7[k], 2048, 13);