Avoid overflow in NetEq's TimeStretch::SpeechDetection

BUG=chromium:675193
R=kwiberg@webrtc.org

Review-Url: https://codereview.webrtc.org/2718943004 .
Cr-Commit-Position: refs/heads/master@{#16902}
This commit is contained in:
Henrik Lundin
2017-02-28 14:58:30 +01:00
parent c6106f4102
commit b1629cf5d6

View File

@ -182,7 +182,8 @@ bool TimeStretch::SpeechDetection(int32_t vec1_energy, int32_t vec2_energy,
// (vec1_energy + vec2_energy) / 16 <= peak_index * background_noise_energy.
// The two sides of the inequality will be denoted |left_side| and
// |right_side|.
int32_t left_side = (vec1_energy + vec2_energy) / 16;
int32_t left_side = rtc::saturated_cast<int32_t>(
(static_cast<int64_t>(vec1_energy) + vec2_energy) / 16);
int32_t right_side;
if (background_noise_.initialized()) {
right_side = background_noise_.Energy(master_channel_);