diff mbox series

[FFmpeg-devel,1/3] avfilter/vf_vif: Fix mismatch in number of array elements

Message ID AM7PR03MB66607420ECD4DEC8CBB81D7E8FF39@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 71eb8f8fa9439cc48a29549ec15a0df1d5eed5ca
Headers show
Series [FFmpeg-devel,1/3] avfilter/vf_vif: Fix mismatch in number of array elements | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 6, 2021, 4:04 p.m. UTC
The function definition used float *data_buf[14], although there are
only 13 elements (and only 13 are used); the declaration used 13.
Given that the type will be converted to float **data_buf anyway,
this is not in violation of the C specs, but nevertheless a bug.

GCC 11 has a new warning for this -Warray-parameter.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_vif.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt Aug. 7, 2021, 10:01 p.m. UTC | #1
Andreas Rheinhardt:
> The function definition used float *data_buf[14], although there are
> only 13 elements (and only 13 are used); the declaration used 13.
> Given that the type will be converted to float **data_buf anyway,
> this is not in violation of the C specs, but nevertheless a bug.
> 
> GCC 11 has a new warning for this -Warray-parameter.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavfilter/vf_vif.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_vif.c b/libavfilter/vf_vif.c
> index a136d038fb..bb949649e4 100644
> --- a/libavfilter/vf_vif.c
> +++ b/libavfilter/vf_vif.c
> @@ -38,6 +38,8 @@
>  #include "vif.h"
>  #include "video.h"
>  
> +#define NUM_DATA_BUFS 13
> +
>  typedef struct VIFContext {
>      const AVClass *class;
>      FFFrameSync fs;
> @@ -46,7 +48,7 @@ typedef struct VIFContext {
>      int height;
>      int nb_threads;
>      float factor;
> -    float *data_buf[13];
> +    float *data_buf[NUM_DATA_BUFS];
>      float **temp;
>      float *ref_data;
>      float *main_data;
> @@ -286,7 +288,7 @@ static int vif_filter1d(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
>  int ff_compute_vif2(AVFilterContext *ctx,
>                      const float *ref, const float *main, int w, int h,
>                      int ref_stride, int main_stride, float *score,
> -                    float *data_buf[14], float **temp,
> +                    float *data_buf[NUM_DATA_BUFS], float **temp,
>                      int gnb_threads)
>  {
>      ThreadData td;
> @@ -515,7 +517,7 @@ static int config_input_ref(AVFilterLink *inlink)
>          s->vif_max[i] = -DBL_MAX;
>      }
>  
> -    for (int i = 0; i < 13; i++) {
> +    for (int i = 0; i < NUM_DATA_BUFS; i++) {
>          if (!(s->data_buf[i] = av_calloc(s->width, s->height * sizeof(float))))
>              return AVERROR(ENOMEM);
>      }
> @@ -608,7 +610,7 @@ static av_cold void uninit(AVFilterContext *ctx)
>                     i, s->vif_sum[i] / s->nb_frames, s->vif_min[i], s->vif_max[i]);
>      }
>  
> -    for (int i = 0; i < 13; i++)
> +    for (int i = 0; i < NUM_DATA_BUFS; i++)
>          av_freep(&s->data_buf[i]);
>  
>      av_freep(&s->ref_data);
> 
Will apply the rest of this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavfilter/vf_vif.c b/libavfilter/vf_vif.c
index a136d038fb..bb949649e4 100644
--- a/libavfilter/vf_vif.c
+++ b/libavfilter/vf_vif.c
@@ -38,6 +38,8 @@ 
 #include "vif.h"
 #include "video.h"
 
+#define NUM_DATA_BUFS 13
+
 typedef struct VIFContext {
     const AVClass *class;
     FFFrameSync fs;
@@ -46,7 +48,7 @@  typedef struct VIFContext {
     int height;
     int nb_threads;
     float factor;
-    float *data_buf[13];
+    float *data_buf[NUM_DATA_BUFS];
     float **temp;
     float *ref_data;
     float *main_data;
@@ -286,7 +288,7 @@  static int vif_filter1d(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 int ff_compute_vif2(AVFilterContext *ctx,
                     const float *ref, const float *main, int w, int h,
                     int ref_stride, int main_stride, float *score,
-                    float *data_buf[14], float **temp,
+                    float *data_buf[NUM_DATA_BUFS], float **temp,
                     int gnb_threads)
 {
     ThreadData td;
@@ -515,7 +517,7 @@  static int config_input_ref(AVFilterLink *inlink)
         s->vif_max[i] = -DBL_MAX;
     }
 
-    for (int i = 0; i < 13; i++) {
+    for (int i = 0; i < NUM_DATA_BUFS; i++) {
         if (!(s->data_buf[i] = av_calloc(s->width, s->height * sizeof(float))))
             return AVERROR(ENOMEM);
     }
@@ -608,7 +610,7 @@  static av_cold void uninit(AVFilterContext *ctx)
                    i, s->vif_sum[i] / s->nb_frames, s->vif_min[i], s->vif_max[i]);
     }
 
-    for (int i = 0; i < 13; i++)
+    for (int i = 0; i < NUM_DATA_BUFS; i++)
         av_freep(&s->data_buf[i]);
 
     av_freep(&s->ref_data);