In some conditions the allocation could run out of bits and attempt to allocate a...
authorGregory Maxwell <greg@xiph.org>
Wed, 29 Oct 2008 00:28:28 +0000 (20:28 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Thu, 30 Oct 2008 03:37:32 +0000 (23:37 -0400)
libcelt/bands.c

index 6a642b3..d2e682f 100644 (file)
@@ -377,10 +377,12 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
       remaining_bits -= curr_bits;
       if (remaining_bits < 0)
       {
-         q--;
          remaining_bits += curr_bits;
-         curr_bits = BPbits[i][q];
-         remaining_bits -= curr_bits;
+         if (q>0) {
+           q--;
+           curr_bits = BPbits[i][q];
+           remaining_bits -= curr_bits;
+         }
       }
       balance += pulses[i] + tell;
       
@@ -462,10 +464,12 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P,
       remaining_bits -= curr_bits;
       if (remaining_bits < 0)
       {
-         q--;
          remaining_bits += curr_bits;
-         curr_bits = BPbits[i][q];
-         remaining_bits -= curr_bits;
+         if (q>0) {
+           q--;
+           curr_bits = BPbits[i][q];
+           remaining_bits -= curr_bits;
+         }
       }
       balance += pulses[i] + tell;