NetEq: Fixing an overflow bug in expand.cc
The overflow currently does not cause any problems, but it has been
found that it can cause crashes after a refactoring that is coming in
the near future.
Bug: webrtc:9180
Change-Id: Ia2c4e545c062c4f8ad13cbc47b8796c6e8a4e906
Reviewed-on: https://webrtc-review.googlesource.com/77667
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23327}
diff --git a/modules/audio_coding/neteq/expand.cc b/modules/audio_coding/neteq/expand.cc
index 03bcc77..73e8d07 100644
--- a/modules/audio_coding/neteq/expand.cc
+++ b/modules/audio_coding/neteq/expand.cc
@@ -743,9 +743,9 @@
// the division.
// Shift the denominator from Q13 to Q5 before the division. The result of
// the division will then be in Q20.
- int temp_ratio = WebRtcSpl_DivW32W16(
- (slope - 8192) << 12,
- static_cast<int16_t>((distortion_lag * slope) >> 8));
+ int16_t denom =
+ rtc::saturated_cast<int16_t>((distortion_lag * slope) >> 8);
+ int temp_ratio = WebRtcSpl_DivW32W16((slope - 8192) << 12, denom);
if (slope > 14746) {
// slope > 1.8.
// Divide by 2, with proper rounding.