Fixes rare overflow in intra_decision()
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Tue, 14 Sep 2010 20:06:22 +0000 (16:06 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Tue, 14 Sep 2010 20:06:22 +0000 (16:06 -0400)
libcelt/quant_bands.c

index 756dab7..8ce3b44 100644 (file)
@@ -74,11 +74,11 @@ static int intra_decision(const celt_word16 *eBands, celt_word16 *oldEBands, int
    {
       for (i=start;i<end;i++)
       {
-         celt_word16 d = SUB16(eBands[i+c*len], oldEBands[i+c*len]);
+         celt_word16 d = SHR16(SUB16(eBands[i+c*len], oldEBands[i+c*len]),1);
          dist = MAC16_16(dist, d,d);
       }
    }
-   return SHR32(dist,2*DB_SHIFT) > 2*C*(end-start);
+   return SHR32(dist,2*DB_SHIFT-2) > 2*C*(end-start);
 }
 
 #ifndef STATIC_MODES