From a1896a649c9238af281a0e73dacbf981d0bc8e64 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Mon, 13 Mar 2017 05:28:47 -0700 Subject: [PATCH] iSAC fix entropy coder: Recently added DCHECK could in fact trigger A DCHECK added in a recent bugfix, which asserted that a signed 64->32 bit cast did not overflow, has been found to not always pass. We fix this by saturating. BUG=chromium:693868 Review-Url: https://codereview.webrtc.org/2746903002 Cr-Commit-Position: refs/heads/master@{#17209} --- webrtc/common_audio/signal_processing/include/spl_inl.h | 5 +++++ .../audio_coding/codecs/isac/fix/source/entropy_coding.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/webrtc/common_audio/signal_processing/include/spl_inl.h b/webrtc/common_audio/signal_processing/include/spl_inl.h index 370834e694..812ab2d587 100644 --- a/webrtc/common_audio/signal_processing/include/spl_inl.h +++ b/webrtc/common_audio/signal_processing/include/spl_inl.h @@ -63,6 +63,11 @@ static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) { #endif } +static __inline int32_t WebRtcSpl_SatW64ToW32(int64_t x) { + int32_t x32 = (int32_t)x; + return x32 == x ? x32 : x < 0 ? INT32_MIN : INT32_MAX; +} + #ifdef WEBRTC_ARCH_ARM_V7 #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" #else diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c index 10e05bc31a..e4d399b61f 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c @@ -234,8 +234,7 @@ static void CalcInvArSpec(const int16_t *ARCoefQ12, for (n = 0; n < FRAMESAMPLES/8; n++) { const int64_t p = (WebRtcIsacfix_kCos[k][n] * (int64_t)CorrQ11[k + 1] + 2) >> 2; - RTC_DCHECK_EQ(p, (int32_t)p); // p fits in 32 bits - CurveQ16[n] += (int32_t)p; + CurveQ16[n] += WebRtcSpl_SatW64ToW32(p); } }