ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Fri May 17 18:51:55 2024 +0200| [e863cbceaeb88082e716dd3b770ed9dfc35ad9e3] | 
committer: Andreas Rheinhardt

avcodec/ac3enc_template: Avoid always-true check

This might also help Coverity with issue #1596532.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e863cbceaeb88082e716dd3b770ed9dfc35ad9e3
---

 libavcodec/ac3enc_template.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 49fc6d7f37..049666fdca 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -31,6 +31,7 @@
 #include <stdint.h>
 
 #include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
 #include "libavutil/mem_internal.h"
 
 #include "audiodsp.h"
@@ -50,14 +51,15 @@
  */
 static void apply_mdct(AC3EncodeContext *s, uint8_t * const *samples)
 {
-    int blk, ch;
+    av_assert1(s->num_blocks > 0);
 
-    for (ch = 0; ch < s->channels; ch++) {
+    for (int ch = 0; ch < s->channels; ch++) {
         const SampleType *input_samples0 = (const 
SampleType*)s->planar_samples[ch];
         /* Reorder channels from native order to AC-3 order. */
         const SampleType *input_samples1 = (const 
SampleType*)samples[s->channel_map[ch]];
+        int blk = 0;
 
-        for (blk = 0; blk < s->num_blocks; blk++) {
+        do {
             AC3Block *block = &s->blocks[blk];
             SampleType *windowed_samples = s->RENAME(windowed_samples);
 
@@ -71,7 +73,8 @@ static void apply_mdct(AC3EncodeContext *s, uint8_t * const 
*samples)
                      windowed_samples, sizeof(*windowed_samples));
             input_samples0  = input_samples1;
             input_samples1 += AC3_BLOCK_SIZE;
-        }
+        } while (++blk < s->num_blocks);
+
         /* Store last 256 samples of current frame */
         memcpy(s->planar_samples[ch], input_samples0,
                AC3_BLOCK_SIZE * sizeof(*input_samples0));

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to