diff mbox series

[FFmpeg-devel,1/3] avfilter/vf_ssim360: Use correct type in sizeof

Message ID AS8P250MB07442C1C4C96DFD125BF43B18FB89@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 1091963d3898eac8aaf8402dc5a5f9867ba96bd1
Headers show
Series [FFmpeg-devel,1/3] avfilter/vf_ssim360: Use correct type in sizeof | 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 March 12, 2023, 9:52 p.m. UTC
SSIM360Context.ssim360_hist is an array of four pointers to double;
so sizeof(*ssim360_hist[0]) (=sizeof(double)) is the correct size
to use to calculate the amount of memory to allocate, not
sizeof(*ssim360_hist) (which is sizeof(double*)).

Use FF_ALLOCZ_TYPED_ARRAY to avoid this issue altogether.

Fixes Coverity issue #1520671.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_ssim360.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jan Ekström March 13, 2023, 10:53 p.m. UTC | #1
On Sun, Mar 12, 2023 at 11:52 PM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> SSIM360Context.ssim360_hist is an array of four pointers to double;
> so sizeof(*ssim360_hist[0]) (=sizeof(double)) is the correct size
> to use to calculate the amount of memory to allocate, not
> sizeof(*ssim360_hist) (which is sizeof(double*)).
>
> Use FF_ALLOCZ_TYPED_ARRAY to avoid this issue altogether.
>
> Fixes Coverity issue #1520671.
>

This set LGTM. Nice fixes and clean-ups in both vf_ssim360 and libx264.

Jan
Anton Khirnov March 14, 2023, 5:43 a.m. UTC | #2
Quoting Andreas Rheinhardt (2023-03-12 22:52:49)
> SSIM360Context.ssim360_hist is an array of four pointers to double;
> so sizeof(*ssim360_hist[0]) (=sizeof(double)) is the correct size
> to use to calculate the amount of memory to allocate, not
> sizeof(*ssim360_hist) (which is sizeof(double*)).
> 
> Use FF_ALLOCZ_TYPED_ARRAY to avoid this issue altogether.
> 
> Fixes Coverity issue #1520671.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavfilter/vf_ssim360.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Looks ok.
diff mbox series

Patch

diff --git a/libavfilter/vf_ssim360.c b/libavfilter/vf_ssim360.c
index 3eb8e43bbc..f8ce0744f2 100644
--- a/libavfilter/vf_ssim360.c
+++ b/libavfilter/vf_ssim360.c
@@ -1624,7 +1624,7 @@  static int config_output(AVFilterLink *outlink)
         memset(s->ssim360_percentile_sum, 0, sizeof(s->ssim360_percentile_sum));
 
         for (int i = 0; i < s->nb_components; i++) {
-            s->ssim360_hist[i] = av_calloc(SSIM360_HIST_SIZE, sizeof(*s->ssim360_hist));
+            FF_ALLOCZ_TYPED_ARRAY(s->ssim360_hist[i], SSIM360_HIST_SIZE);
             if (!s->ssim360_hist[i])
                 return AVERROR(ENOMEM);
         }