avcodec/ac3enc_template: fix out of array read
[ffmpeg.git] / libavcodec / ac3enc_template.c
index 29e2381c9dfa08ce5f6b49f7675c15c96405a0e3..f1f81da290ffbe286f006a5794772c23c530bbfe 100644 (file)
@@ -263,7 +263,7 @@ static void apply_channel_coupling(AC3EncodeContext *s)
                 energy_cpl = energy[blk][CPL_CH][bnd];
                 energy_ch = energy[blk][ch][bnd];
                 blk1 = blk+1;
-                while (!s->blocks[blk1].new_cpl_coords[ch] && blk1 < s->num_blocks) {
+                while (blk1 < s->num_blocks && !s->blocks[blk1].new_cpl_coords[ch]) {
                     if (s->blocks[blk1].cpl_in_use) {
                         energy_cpl += energy[blk1][CPL_CH][bnd];
                         energy_ch += energy[blk1][ch][bnd];