From 5663ce91529a5a2b58cf4eff151ee7fb442f207c Mon Sep 17 00:00:00 2001 From: Minyue Li Date: Fri, 23 Apr 2021 00:58:24 +0200 Subject: [PATCH] Avoid undefined behavior in a division operation. BUG: webrtc:5486 Change-Id: I2850fbec3283b81b49ee4f966349a94aabc2bf82 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215969 Reviewed-by: Henrik Lundin Reviewed-by: Artem Titov Commit-Queue: Minyue Li Cr-Commit-Position: refs/heads/master@{#33811} --- common_audio/signal_processing/division_operations.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common_audio/signal_processing/division_operations.c b/common_audio/signal_processing/division_operations.c index c6195e7999..4764ddfccd 100644 --- a/common_audio/signal_processing/division_operations.c +++ b/common_audio/signal_processing/division_operations.c @@ -98,8 +98,7 @@ int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den) return div; } -int32_t RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486 -WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) +int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) { int16_t approx, tmp_hi, tmp_low, num_hi, num_low; int32_t tmpW32; @@ -111,8 +110,8 @@ WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1); // tmpW32 = den * approx - tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx)) - // UBSan: 2147483647 - -2 cannot be represented in type 'int' + // result in Q30 (tmpW32 = 2.0-(den*approx)) + tmpW32 = (int32_t)((int64_t)0x7fffffffL - tmpW32); // Store tmpW32 in hi and low format tmp_hi = (int16_t)(tmpW32 >> 16);