diff mbox series

[FFmpeg-devel,1/2] avcodec/ac3enc_template: Avoid always-true check

Message ID AS8P250MB07440CB25403CF0260C2F5758FEE2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit e863cbceaeb88082e716dd3b770ed9dfc35ad9e3
Headers show
Series [FFmpeg-devel,1/2] avcodec/ac3enc_template: Avoid always-true check | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt May 17, 2024, 5:57 p.m. UTC
This might also help Coverity with issue #1596532.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ac3enc_template.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt May 19, 2024, 9:48 a.m. UTC | #1
Andreas Rheinhardt:
> This might also help Coverity with issue #1596532.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  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));

 Will apply this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

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));