Fixes a (harmless) numerical overflow in noise_shape_analysis_FIX.c
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Wed, 25 Apr 2012 00:45:04 +0000 (20:45 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Wed, 25 Apr 2012 00:45:04 +0000 (20:45 -0400)
Actual behaviour was correct on most architectures and breaking that
code would have required a particularly smart compiler.

silk/fixed/noise_shape_analysis_FIX.c

index f31d4ef..b0e35de 100644 (file)
@@ -311,9 +311,10 @@ void silk_noise_shape_analysis_FIX(
             /* Adjust gain for warping */
             gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder );
             silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );
-            psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
-            if( psEncCtrl->Gains_Q16[ k ] < 0 ) {
-                psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX;
+            if ( silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ), gain_mult_Q16 ) >= ( silk_int32_MAX >> 1 ) ) {
+               psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX;
+            } else {
+               psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
             }
         }