PR #20663 opened by Baptiste Coudurier (bcoudurier)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20663
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20663.patch

in the earlier argument and not in the later argument [-Wcalloc-transposed-args]

Fixes trac ticket #11620


>From ef60d5ac32a71d62e09630acc73b56f09a7d5ef2 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Fri, 6 Jun 2025 13:42:28 -0700
Subject: [PATCH] general: fix warning 'av_malloc_array' sizes specified with
 'sizeof' in the earlier argument and not in the later argument
 [-Wcalloc-transposed-args]

Fixes trac ticket #11620
---
 libavcodec/dsddec.c            |  2 +-
 libavcodec/vaapi_encode.c      |  4 ++--
 libavcodec/vorbisenc.c         | 10 +++++-----
 libavfilter/af_arnndn.c        |  6 +++---
 libavfilter/af_astats.c        |  2 +-
 libavfilter/af_silencedetect.c |  2 +-
 libavfilter/formats.c          |  2 +-
 libavfilter/vf_libopencv.c     |  2 +-
 libavfilter/vf_pixdesctest.c   |  2 +-
 libavutil/hwcontext_vulkan.c   |  2 +-
 libavutil/side_data.c          |  2 +-
 11 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c
index 793cfc9f06..aa8577d667 100644
--- a/libavcodec/dsddec.c
+++ b/libavcodec/dsddec.c
@@ -52,7 +52,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     ff_init_dsd_data();
 
-    s = av_malloc_array(sizeof(DSDContext), avctx->ch_layout.nb_channels);
+    s = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*s));
     if (!s)
         return AVERROR(ENOMEM);
 
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index ed62347c06..0e50602e1f 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -52,7 +52,7 @@ static int vaapi_encode_make_packed_header(AVCodecContext 
*avctx,
         .has_emulation_bytes = 1,
     };
 
-    tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), 
pic->nb_param_buffers + 2);
+    tmp = av_realloc_array(pic->param_buffers, pic->nb_param_buffers + 2, 
sizeof(*tmp));
     if (!tmp)
         return AVERROR(ENOMEM);
     pic->param_buffers = tmp;
@@ -93,7 +93,7 @@ static int vaapi_encode_make_param_buffer(AVCodecContext 
*avctx,
     VABufferID *tmp;
     VABufferID buffer;
 
-    tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), 
pic->nb_param_buffers + 1);
+    tmp = av_realloc_array(pic->param_buffers, pic->nb_param_buffers + 1, 
sizeof(*tmp));
     if (!tmp)
         return AVERROR(ENOMEM);
     pic->param_buffers = tmp;
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index b4680a11ed..ab30dd49ed 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -463,11 +463,11 @@ static int create_vorbis_context(vorbis_enc_context *venc,
     venc->modes[1].mapping   = 0;
 
     venc->have_saved = 0;
-    venc->saved      = av_malloc_array(sizeof(float) * venc->channels, (1 << 
venc->log2_blocksize[1]) / 2);
-    venc->samples    = av_malloc_array(sizeof(float) * venc->channels, (1 << 
venc->log2_blocksize[1]));
-    venc->floor      = av_malloc_array(sizeof(float) * venc->channels, (1 << 
venc->log2_blocksize[1]) / 2);
-    venc->coeffs     = av_malloc_array(sizeof(float) * venc->channels, (1 << 
venc->log2_blocksize[1]) / 2);
-    venc->scratch    = av_malloc_array(sizeof(float) * venc->channels, (1 << 
venc->log2_blocksize[1]));
+    venc->saved      = av_malloc_array((1 << venc->log2_blocksize[1]) / 2, 
sizeof(float) * venc->channels);
+    venc->samples    = av_malloc_array((1 << venc->log2_blocksize[1]), 
sizeof(float) * venc->channels);
+    venc->floor      = av_malloc_array((1 << venc->log2_blocksize[1]) / 2, 
sizeof(float) * venc->channels);
+    venc->coeffs     = av_malloc_array((1 << venc->log2_blocksize[1]) / 2, 
sizeof(float) * venc->channels);
+    venc->scratch    = av_malloc_array((1 << venc->log2_blocksize[1]), 
sizeof(float) * venc->channels);
 
     if (!venc->saved || !venc->samples || !venc->floor || !venc->coeffs || 
!venc->scratch)
         return AVERROR(ENOMEM);
diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index 27a35c8492..8bdc218781 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -361,9 +361,9 @@ static int config_input(AVFilterLink *inlink)
         DenoiseState *st = &s->st[i];
 
         st->rnn[0].model = s->model[0];
-        st->rnn[0].vad_gru_state = av_calloc(sizeof(float), 
FFALIGN(s->model[0]->vad_gru_size, 16));
-        st->rnn[0].noise_gru_state = av_calloc(sizeof(float), 
FFALIGN(s->model[0]->noise_gru_size, 16));
-        st->rnn[0].denoise_gru_state = av_calloc(sizeof(float), 
FFALIGN(s->model[0]->denoise_gru_size, 16));
+        st->rnn[0].vad_gru_state = 
av_calloc(FFALIGN(s->model[0]->vad_gru_size, 16), sizeof(float));
+        st->rnn[0].noise_gru_state = 
av_calloc(FFALIGN(s->model[0]->noise_gru_size, 16), sizeof(float));
+        st->rnn[0].denoise_gru_state = 
av_calloc(FFALIGN(s->model[0]->denoise_gru_size, 16), sizeof(float));
         if (!st->rnn[0].vad_gru_state ||
             !st->rnn[0].noise_gru_state ||
             !st->rnn[0].denoise_gru_state)
diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
index e5be00ec0b..6ef69ff102 100644
--- a/libavfilter/af_astats.c
+++ b/libavfilter/af_astats.c
@@ -210,7 +210,7 @@ static int config_output(AVFilterLink *outlink)
 {
     AudioStatsContext *s = outlink->src->priv;
 
-    s->chstats = av_calloc(sizeof(*s->chstats), 
outlink->ch_layout.nb_channels);
+    s->chstats = av_calloc(outlink->ch_layout.nb_channels, 
sizeof(*s->chstats));
     if (!s->chstats)
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c
index 532f6b08af..bcdc90f8e3 100644
--- a/libavfilter/af_silencedetect.c
+++ b/libavfilter/af_silencedetect.c
@@ -176,7 +176,7 @@ static int config_input(AVFilterLink *inlink)
                                    sizeof(*s->nb_null_samples));
     if (!s->nb_null_samples)
         return AVERROR(ENOMEM);
-    s->start = av_malloc_array(sizeof(*s->start), s->independent_channels);
+    s->start = av_malloc_array(s->independent_channels, sizeof(*s->start));
     if (!s->start)
         return AVERROR(ENOMEM);
     for (c = 0; c < s->independent_channels; c++)
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 11a0f13ac6..847199dda1 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -688,7 +688,7 @@ AVFilterFormats *ff_all_alpha_modes(void)
     if (!f)                                                                    
 \
         return AVERROR(ENOMEM);                                                
 \
                                                                                
 \
-    tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1);        
 \
+    tmp = av_realloc_array(f->refs, f->refcount + 1, sizeof(*f->refs));        
 \
     if (!tmp) {                                                                
 \
         unref_fn(&f);                                                          
 \
         return AVERROR(ENOMEM);                                                
 \
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index 7dc27144fe..fb78e10faf 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -165,7 +165,7 @@ static int read_shape_from_file(int *cols, int *rows, int 
**values, const char *
         ret = AVERROR_INVALIDDATA;
         goto end;
     }
-    if (!(*values = av_calloc(sizeof(int) * *rows, *cols))) {
+    if (!(*values = av_calloc(*cols, sizeof(**values) * *rows))) {
         ret = AVERROR(ENOMEM);
         goto end;
     }
diff --git a/libavfilter/vf_pixdesctest.c b/libavfilter/vf_pixdesctest.c
index 994fe1db93..9dcd0c6192 100644
--- a/libavfilter/vf_pixdesctest.c
+++ b/libavfilter/vf_pixdesctest.c
@@ -48,7 +48,7 @@ static int config_props(AVFilterLink *inlink)
     priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
 
     av_freep(&priv->line);
-    if (!(priv->line = av_malloc_array(sizeof(*priv->line), inlink->w)))
+    if (!(priv->line = av_malloc_array(inlink->w, sizeof(*priv->line))))
         return AVERROR(ENOMEM);
 
     return 0;
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 47f894f75f..286e13c509 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -714,7 +714,7 @@ static VkBool32 VKAPI_CALL 
vk_dbg_callback(VkDebugUtilsMessageSeverityFlagBitsEX
 
 #define ADD_VAL_TO_LIST(list, count, val)                                      
\
     do {                                                                       
\
-        list = av_realloc_array(list, sizeof(*list), ++count);                 
\
+        list = av_realloc_array(list, ++count, sizeof(*list));                 
\
         if (!list) {                                                           
\
             err = AVERROR(ENOMEM);                                             
\
             goto fail;                                                         
\
diff --git a/libavutil/side_data.c b/libavutil/side_data.c
index 8df117478a..bbbeb70ecd 100644
--- a/libavutil/side_data.c
+++ b/libavutil/side_data.c
@@ -151,7 +151,7 @@ static AVFrameSideData 
*add_side_data_from_buf_ext(AVFrameSideData ***sd,
     if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX))
         return NULL;
 
-    tmp = av_realloc_array(*sd, sizeof(**sd), *nb_sd + 1);
+    tmp = av_realloc_array(*sd, *nb_sd + 1, sizeof(**sd));
     if (!tmp)
         return NULL;
     *sd = tmp;
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to