diff --git a/libcelt/bands.c b/libcelt/bands.c
index 6a642b3c78a5bdbb8a40aba6db2dc362e4c4c045..d2e682f7b4356778e41b5479cf4b2f24f5e83099 100644
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -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;