[FFmpeg-cvslog] fftools/avtextformat: Re-use BPrint in loop
softworkz
git at videolan.org
Fri May 16 00:11:26 EEST 2025
ffmpeg | branch: master | softworkz <softworkz at hotmail.com> | Thu Apr 24 02:32:13 2025 +0200| [4ff90f05c7a964b7ec651d494efc43eabcf8d60b] | committer: softworkz
fftools/avtextformat: Re-use BPrint in loop
Instead of initializing a new BPrint in case of UTF decode error,
re-use the same BPrint struct and just clear it
for each iteration.
Reviewed-by: Stefano Sabatini <stefasab at gmail.com>
Signed-off-by: softworkz <softworkz at hotmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4ff90f05c7a964b7ec651d494efc43eabcf8d60b
---
fftools/textformat/avtextformat.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c
index 8ee7472f1b..ec167e3bf1 100644
--- a/fftools/textformat/avtextformat.c
+++ b/fftools/textformat/avtextformat.c
@@ -311,24 +311,28 @@ void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t va
static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
{
- const uint8_t *p, *endp;
+ const uint8_t *p, *endp, *srcp = (const uint8_t *)src;
AVBPrint dstbuf;
+ AVBPrint invalid_seq;
int invalid_chars_nb = 0, ret = 0;
+ *dstp = NULL;
av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
+ av_bprint_init(&invalid_seq, 0, AV_BPRINT_SIZE_UNLIMITED);
- endp = src + strlen(src);
- for (p = src; *p;) {
- uint32_t code;
+ endp = srcp + strlen(src);
+ for (p = srcp; *p;) {
+ int32_t code;
int invalid = 0;
const uint8_t *p0 = p;
if (av_utf8_decode(&code, &p, endp, tctx->string_validation_utf8_flags) < 0) {
- AVBPrint bp;
- av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
- bprint_bytes(&bp, p0, p-p0);
- av_log(tctx, AV_LOG_DEBUG,
- "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
+
+ av_bprint_clear(&invalid_seq);
+
+ bprint_bytes(&invalid_seq, p0, p - p0);
+
+ av_log(tctx, AV_LOG_DEBUG, "Invalid UTF-8 sequence '%s' found in string '%s'\n", invalid_seq.str, src);
invalid = 1;
}
@@ -358,6 +362,7 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const
end:
av_bprint_finalize(&dstbuf, dstp);
+ av_bprint_finalize(&invalid_seq, NULL);
return ret;
}
More information about the ffmpeg-cvslog
mailing list