Fixes some fixed-point 16-bit int overflows v1.2-beta
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Wed, 24 May 2017 05:21:51 +0000 (01:21 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Wed, 24 May 2017 05:21:51 +0000 (01:21 -0400)
The code would have run fine on 32-bit archs, but would have overflowed
on a 16-bit arch

celt/celt_encoder.c
celt/pitch.c

index 6d88472..4851208 100644 (file)
@@ -843,7 +843,7 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
    } 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
index bf46e7d..42f526b 100644 (file)
@@ -424,7 +424,7 @@ static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy
    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)
       {