PR #25469 opened by Kilian (lusoris)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25469
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25469.patch

This test-only patch addresses GCC 14.4.0 and 16.2.1 -Wstack-usage diagnostics 
against -Wstack-usage=122880 in libswresample/tests/swresample.c.

What the patch does:

- `swresample/tests/swresample: allocate sample buffers and test indices`: 
replaces large automatic sample buffers and the remaining-test index array with 
heap allocations after argument parsing, replaces local alignment declarations, 
checks allocation failures and frees storage through the existing cleanup path.

Behaviour change: test-only allocations can fail; buffer capacities, test 
selection and sample processing are unchanged when allocation succeeds.

Base: FFmpeg master 46f23be8b1.

Testing:

- GCC 14.4.0 (`--enable-gpl --enable-vulkan`) and GCC 16.2.1 (`--enable-gpl 
--enable-vulkan --enable-vaapi --enable-libdrm --enable-nvenc`), targets all, 
alltools, examples, testprogs and checkasm: master 46f23be8b1 shows 1 
-Wstack-usage warning in libswresample/tests/swresample.c with each compiler; 
with this patch there are none and no new ones.
- FATE with GCC 16.2.1, `fate-swr*` tests (414 tests): all pass on master and 
with this patch.

Split out of #25111 so that each part reaches the reviewers for its area.



>From 797497c7ae676ced2c6c66c017283e381fc2642d Mon Sep 17 00:00:00 2001
From: lusoris <[email protected]>
Date: Thu, 15 Oct 2026 22:06:37 +0200
Subject: [PATCH] swresample/tests/swresample: allocate sample buffers and test
 indices

GCC 14.4.0 and 16.2.1 report -Wstack-usage against FFmpeg's default
-Wstack-usage=122880 limit. The sample buffers and remaining-test index
array occupy large automatic storage. Allocate them after argument
parsing, check allocation failures and free them through the existing
cleanup path. Buffer capacities, test selection and sample processing
are unchanged when allocation succeeds.

Signed-off-by: lusoris <[email protected]>
---
 libswresample/tests/swresample.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/libswresample/tests/swresample.c b/libswresample/tests/swresample.c
index 8ee35e1e218..1eb858bd81a 100644
--- a/libswresample/tests/swresample.c
+++ b/libswresample/tests/swresample.c
@@ -22,7 +22,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
-#include "libavutil/mem_internal.h"
+#include "libavutil/mem.h"
 #include "libavutil/opt.h"
 
 #include "libswresample/swresample.h"
@@ -223,9 +223,9 @@ int main(int argc, char **argv){
     int in_sample_rate, out_sample_rate, ch ,i, flush_count;
     AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
     enum AVSampleFormat in_sample_fmt, out_sample_fmt;
-    LOCAL_ALIGNED(32, uint8_t, array_in,  [SAMPLES*8*8]);
-    LOCAL_ALIGNED(32, uint8_t, array_mid, [SAMPLES*8*8*3]);
-    LOCAL_ALIGNED(32, uint8_t, array_out, [SAMPLES*8*8+100]);
+    uint8_t *array_in = NULL;
+    uint8_t *array_mid = NULL;
+    uint8_t *array_out = NULL;
     uint8_t *ain[SWR_CH_MAX];
     uint8_t *aout[SWR_CH_MAX];
     uint8_t *amid[SWR_CH_MAX];
@@ -234,8 +234,10 @@ int main(int argc, char **argv){
     int num_tests = 10000;
     uint32_t seed = 0;
     uint32_t rand_seed = 0;
-    int remaining_tests[FF_ARRAY_ELEMS(rates) * FF_ARRAY_ELEMS(layouts) * 
FF_ARRAY_ELEMS(formats) * FF_ARRAY_ELEMS(layouts) * FF_ARRAY_ELEMS(formats)];
-    int max_tests = FF_ARRAY_ELEMS(remaining_tests);
+    const int max_tests = FF_ARRAY_ELEMS(rates) * FF_ARRAY_ELEMS(layouts) *
+                          FF_ARRAY_ELEMS(formats) * FF_ARRAY_ELEMS(layouts) *
+                          FF_ARRAY_ELEMS(formats);
+    int *remaining_tests = NULL;
     int test;
     int specific_test= -1;
     int ret = 0;
@@ -261,6 +263,16 @@ int main(int argc, char **argv){
         }
     }
 
+    array_in = av_malloc(SAMPLES * 8 * 8);
+    array_mid = av_malloc(SAMPLES * 8 * 8 * 3);
+    array_out = av_malloc(SAMPLES * 8 * 8 + 100);
+    remaining_tests = av_malloc_array(max_tests, sizeof(*remaining_tests));
+    if (!array_in || !array_mid || !array_out || !remaining_tests) {
+        fprintf(stderr, "Failed to allocate test buffers\n");
+        ret = 1;
+        goto end;
+    }
+
     for(i=0; i<max_tests; i++)
         remaining_tests[i] = i;
 
@@ -415,5 +427,9 @@ end:
     swr_free(&backw_ctx);
     av_channel_layout_uninit(&in_ch_layout);
     av_channel_layout_uninit(&out_ch_layout);
+    av_free(array_in);
+    av_free(array_mid);
+    av_free(array_out);
+    av_free(remaining_tests);
     return ret;
 }
-- 
2.54.0

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

Reply via email to