From 6999980d671f70fdae19c8b4663efa5189f9ca6c Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Sat, 11 Aug 2012 21:56:42 +0300 Subject: Use saturating adds to avoid overflow When the addition overflowed, asserts were triggered later, where the values were assumed to be non-negative. --- libSBRenc/src/env_est.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libSBRenc/src/env_est.cpp b/libSBRenc/src/env_est.cpp index 9423f27..312e0ae 100644 --- a/libSBRenc/src/env_est.cpp +++ b/libSBRenc/src/env_est.cpp @@ -762,8 +762,8 @@ calculateSbrEnvelope (FIXP_DBL **RESTRICT YBufferLeft, /*! energy buffer left * /* save energies */ pNrgLeft[j] = nrgLeft; pNrgRight[j] = nrgRight; - envNrgLeft += nrgLeft; - envNrgRight += nrgRight; + envNrgLeft = fAddSaturate(envNrgLeft, nrgLeft); + envNrgRight = fAddSaturate(envNrgRight, nrgRight); } /* j */ -- cgit v1.2.3