[FFmpeg-devel] [PATCH 3/6] tools/target_dec_fuzzer: suppress Wdeclaration-after-statement

Kacper Michajłow kasper93 at gmail.com
Sun Apr 6 03:39:20 EEST 2025


To avoid spam in log, each fuzzer is built separately so it's amplified
a lot.

Signed-off-by: Kacper Michajłow <kasper93 at gmail.com>
---
 tools/target_dec_fuzzer.c | 41 +++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index de0419430f..a15f1a3f9c 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -166,6 +166,12 @@ static int fuzz_get_buffer2(AVCodecContext *ctx, AVFrame *frame, int flags)
     }
 }
 
+#define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
+#define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC)
+
+extern FFCodec DECODER_SYMBOL(FFMPEG_DECODER);
+extern FFCodec DECODER_SYMBOL(mjpeg);
+
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     uint64_t maxpixels_per_frame = 4096 * 4096;
     uint64_t maxpixels;
@@ -185,16 +191,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     uint64_t keyframes = 0;
     uint64_t flushpattern = -1;
     AVDictionary *opts = NULL;
+    AVCodecContext* ctx;
+    AVCodecContext* parser_avctx;
+    AVFrame *frame;
+    AVPacket *avpkt;
+    AVPacket *parsepkt;
+    int res;
+    int got_frame;
 
     if (!c) {
 #ifdef FFMPEG_DECODER
-#define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
-#define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC)
-        extern FFCodec DECODER_SYMBOL(FFMPEG_DECODER);
         codec_list[0] = &DECODER_SYMBOL(FFMPEG_DECODER);
 
 #if defined(FFMPEG_DECODER_tiff) || defined(FFMPEG_DECODER_tdsc)
-        extern FFCodec DECODER_SYMBOL(mjpeg);
         codec_list[1] = &DECODER_SYMBOL(mjpeg);
 #endif
 
@@ -341,8 +350,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     maxsamples_per_frame = FFMIN(maxsamples_per_frame, maxsamples);
     maxpixels_per_frame  = FFMIN(maxpixels_per_frame , maxpixels);
 
-    AVCodecContext* ctx = avcodec_alloc_context3(&c->p);
-    AVCodecContext* parser_avctx = avcodec_alloc_context3(NULL);
+    ctx = avcodec_alloc_context3(&c->p);
+    parser_avctx = avcodec_alloc_context3(NULL);
     if (!ctx || !parser_avctx)
         error("Failed memory allocation");
 
@@ -472,7 +481,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
             ctx->width = ctx->height = 0;
     }
 
-    int res = avcodec_open2(ctx, &c->p, &opts);
+    res = avcodec_open2(ctx, &c->p, &opts);
     if (res < 0) {
         avcodec_free_context(&ctx);
         av_free(parser_avctx);
@@ -484,11 +493,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     parser_avctx->extradata_size = ctx->extradata_size;
     parser_avctx->extradata      = ctx->extradata ? av_memdup(ctx->extradata, ctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE) : NULL;
 
-
-    int got_frame;
-    AVFrame *frame = av_frame_alloc();
-    AVPacket *avpkt = av_packet_alloc();
-    AVPacket *parsepkt = av_packet_alloc();
+    frame = av_frame_alloc();
+    avpkt = av_packet_alloc();
+    parsepkt = av_packet_alloc();
     if (!frame || !avpkt || !parsepkt)
         error("Failed memory allocation");
 
@@ -563,7 +570,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
           // Iterate through all data
           while (decode_more && it++ < maxiteration) {
             av_frame_unref(frame);
-            int ret = decode_handler(ctx, frame, &got_frame, avpkt);
+            res = decode_handler(ctx, frame, &got_frame, avpkt);
 
             ec_pixels += (ctx->width + 32LL) * (ctx->height + 32LL);
             if (it > 20 || ec_pixels > 4 * ctx->max_pixels) {
@@ -582,15 +589,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
             if (nb_samples > maxsamples)
                 goto maximums_reached;
 
-            if (ret <= 0 || ret > avpkt->size)
+            if (res <= 0 || res > avpkt->size)
                break;
 
             if (ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-                avpkt->data += ret;
-                avpkt->size -= ret;
+                avpkt->data += res;
+                avpkt->size -= res;
                 decode_more = avpkt->size > 0;
             } else
-                decode_more = ret >= 0;
+                decode_more = res >= 0;
           }
           av_packet_unref(avpkt);
         }
-- 
2.49.0



More information about the ffmpeg-devel mailing list