shithub: opus

Download patch

ref: 3609a2218e05abc96bb9b5edd875ec16a92ba699
parent: a671ac5582fe598f3a46e659873eb7bbc9010cb1
author: Jean-Marc Valin <[email protected]>
date: Tue May 23 21:21:51 EDT 2017

Fixes some fixed-point 16-bit int overflows

The code would have run fine on 32-bit archs, but would have overflowed
on a 16-bit arch

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -843,7 +843,7 @@
    } while (++c<C);
    diff /= C*(end-1);
    /*printf("%f\n", diff);*/
-   trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), SHR16(diff+QCONST16(1.f, DB_SHIFT),DB_SHIFT-8)/6 ));
+   trim -= MAX32(-QCONST16(2.f, 8), MIN32(QCONST16(2.f, 8), SHR32(diff+QCONST16(1.f, DB_SHIFT),DB_SHIFT-8)/6 ));
    trim -= SHR16(surround_trim, DB_SHIFT-8);
    trim -= 2*SHR16(tf_estimate, 14-8);
 #ifndef DISABLE_FLOAT_API
--- a/celt/pitch.c
+++ b/celt/pitch.c
@@ -424,7 +424,7 @@
    sx = celt_ilog2(xx)-14;
    sy = celt_ilog2(yy)-14;
    shift = sx + sy;
-   x2y2 = MULT16_16_Q14(VSHR32(xx, sx), VSHR32(yy, sy));
+   x2y2 = SHR32(MULT16_16(VSHR32(xx, sx), VSHR32(yy, sy)), 14);
    if (shift & 1) {
       if (x2y2 < 32768)
       {