Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PR] avfilter/af_loudnorm: Avoid unchecked allocation (PR #21795)
@ 2026-02-19 13:30 mkver via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: mkver via ffmpeg-devel @ 2026-02-19 13:30 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: mkver

PR #21795 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21795
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21795.patch

Also deduplicate printing json and summary output.


>From 4d5e74ac2f88aad895ff64329ee1384fd12ed2a7 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 19 Feb 2026 14:26:33 +0100
Subject: [PATCH] avfilter/af_loudnorm: Avoid unchecked allocation

Also deduplicate printing json and summary output.

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

diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index e9cc40baa6..17b819b185 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -20,7 +20,6 @@
 
 /* http://k.ylo.ph/2016/04/04/loudnorm.html */
 
-#include "libavutil/avstring.h"
 #include "libavutil/file_open.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -834,7 +833,6 @@ static av_cold void uninit(AVFilterContext *ctx)
     double i_in, i_out, lra_in, lra_out, thresh_in, thresh_out, tp_in, tp_out;
     int c;
     FILE *stats_file = NULL;
-    char *stats = NULL;
 
     if (!s->r128_in || !s->r128_out)
         goto end;
@@ -879,7 +877,9 @@ static av_cold void uninit(AVFilterContext *ctx)
         break;
 
     case JSON:
-        stats = av_asprintf(
+    case SUMMARY: {
+        char stats[1024];
+        const char *const format = s->print_format == JSON ?
             "{\n"
             "\t\"input_i\" : \"%.2f\",\n"
             "\t\"input_tp\" : \"%.2f\",\n"
@@ -891,25 +891,7 @@ static av_cold void uninit(AVFilterContext *ctx)
             "\t\"output_thresh\" : \"%.2f\",\n"
             "\t\"normalization_type\" : \"%s\",\n"
             "\t\"target_offset\" : \"%.2f\"\n"
-            "}\n",
-            i_in,
-            20. * log10(tp_in),
-            lra_in,
-            thresh_in,
-            i_out,
-            20. * log10(tp_out),
-            lra_out,
-            thresh_out,
-            s->frame_type == LINEAR_MODE ? "linear" : "dynamic",
-            s->target_i - i_out
-        );
-        av_log(ctx, AV_LOG_INFO, "\n%s", stats);
-        if (stats_file)
-            fprintf(stats_file, "%s", stats);
-        break;
-
-    case SUMMARY:
-        stats = av_asprintf(
+            "}\n" :
             "Input Integrated:   %+6.1f LUFS\n"
             "Input True Peak:    %+6.1f dBTP\n"
             "Input LRA:          %6.1f LU\n"
@@ -921,7 +903,9 @@ static av_cold void uninit(AVFilterContext *ctx)
             "Output Threshold:   %+6.1f LUFS\n"
             "\n"
             "Normalization Type:   %s\n"
-            "Target Offset:      %+6.1f LU\n",
+            "Target Offset:      %+6.1f LU\n";
+
+        snprintf(stats, sizeof(stats), format,
             i_in,
             20. * log10(tp_in),
             lra_in,
@@ -930,7 +914,8 @@ static av_cold void uninit(AVFilterContext *ctx)
             20. * log10(tp_out),
             lra_out,
             thresh_out,
-            s->frame_type == LINEAR_MODE ? "Linear" : "Dynamic",
+            s->frame_type == LINEAR_MODE ? (s->print_format == JSON ? "linear"  : "Linear")
+                                         : (s->print_format == JSON ? "dynamic" : "Dynamic"),
             s->target_i - i_out
         );
         av_log(ctx, AV_LOG_INFO, "\n%s", stats);
@@ -938,10 +923,9 @@ static av_cold void uninit(AVFilterContext *ctx)
             fprintf(stats_file, "%s", stats);
         break;
     }
+    }
 
 end:
-    if (stats)
-        av_free(stats);
     if (stats_file && stats_file != stdout)
         fclose(stats_file);
     if (s->r128_in)
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-02-19 13:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-19 13:30 [FFmpeg-devel] [PR] avfilter/af_loudnorm: Avoid unchecked allocation (PR #21795) mkver via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git