Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 956c3a2c authored by Ray Essick's avatar Ray Essick
Browse files

Avoid add overflow in summation in AMR-WB decoder

codec look was doing a int32+= int16*int16 MAC which was overflowing
instead of saturating. Standard  3GPP #26.173 says it should saturate.

Bug: 112160454
Test: poc no longer crashes
Change-Id: I2979425be6b5b7b1dbe6790daf431fc86ab591c5
parent b98450a7
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -467,7 +467,12 @@ extern "C"
    __inline  int32 fxp_mac_16by16(int16 var1,  int16 var2, int32 L_add)
    {

        L_add += (int32)var1 * var2;
        int32 l_orig = L_add;
        if (__builtin_add_overflow( (int32)var1 * var2, l_orig, &L_add)) {
            // needs saturation
            if (l_orig > 0) L_add = MAX_32;
            else            L_add = MIN_32;
        }

        return L_add;
    }