diff options
author | Koen Vos <koenvos@users.noreply.github.com> | 2016-05-31 21:18:21 +0800 |
---|---|---|
committer | Koen Vos <koenvos@users.noreply.github.com> | 2016-05-31 21:18:21 +0800 |
commit | 6600e72f47b1aa3d8e4a0e8da1d48a3624c2c2f5 (patch) | |
tree | a55b5079dba2905dc411ca30c45bb67d1a46b2b5 | |
parent | b4778904c8ebd79bc628305717f908e635797c3d (diff) | |
download | opus-6600e72f47b1aa3d8e4a0e8da1d48a3624c2c2f5.tar.gz |
fix potential overflow
-rw-r--r-- | silk/sum_sqr_shift.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/silk/sum_sqr_shift.c b/silk/sum_sqr_shift.c index eb5a910e..667cc0e0 100644 --- a/silk/sum_sqr_shift.c +++ b/silk/sum_sqr_shift.c @@ -70,6 +70,11 @@ void silk_sum_sqr_shift( /* One sample left to process */ nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); + if( nrg < 0 ) { + /* Scale down */ + nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 1 ); + shft++; + } } /* Make sure to have at least 10% headroom */ |