diff --git a/libcelt/modes.c b/libcelt/modes.c
index 4d39417d96ecd32cba58ad5d8753712cf5391cb8..7649143a776a266034009374f224651e7aed0828 100644
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -214,7 +214,7 @@ static void compute_allocation_table(CELTMode *mode)
             if (400*(celt_int32)eband5ms[k] > mode->eBands[j]*(celt_int32)mode->Fs/mode->shortMdctSize)
                break;
          }
-         if (k>mode->nbEBands-1)
+         if (k>maxBands-1)
             allocVectors[i*mode->nbEBands+j] = band_allocation[i*maxBands + maxBands-1];
          else {
             celt_int32 a0, a1;