PR #26224 opened by Pu Cheng (GeekQAQ)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26224
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26224.patch

av_bprint_clear() only writes the terminating 0 when len is not 0.
Bytes written directly into the buffer obtained from
av_bprint_get_buffer() do not update len, so clearing the buffer after
such a write leaves the written string in place, contrary to the
documentation ("Reset the string to "" but keep internal allocated
data").

Write the terminator unconditionally.

Signed-off-by: Pu Cheng <[email protected]>



>From 34bb78b298b88a7df7554075c4b0fe593ec4a1ca Mon Sep 17 00:00:00 2001
From: Pu Cheng <[email protected]>
Date: Fri, 20 Nov 2026 14:34:00 +0800
Subject: [PATCH] avutil/bprint: always terminate the string in
 av_bprint_clear()

av_bprint_clear() only writes the terminating 0 when len is not 0.
Bytes written directly into the buffer obtained from
av_bprint_get_buffer() do not update len, so clearing the buffer after
such a write leaves the written string in place, contrary to the
documentation ("Reset the string to "" but keep internal allocated
data").

Write the terminator unconditionally.

Signed-off-by: Pu Cheng <[email protected]>
---
 libavutil/bprint.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 3c6d14c2e96..cc8f37c0373 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -225,10 +225,8 @@ void av_bprint_get_buffer(AVBPrint *buf, unsigned size,
 
 void av_bprint_clear(AVBPrint *buf)
 {
-    if (buf->len) {
-        *buf->str = 0;
-        buf->len  = 0;
-    }
+    *buf->str = 0;
+    buf->len  = 0;
 }
 
 int av_bprint_finalize(AVBPrint *buf, char **ret_str)
-- 
2.54.1

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

Reply via email to