History

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.

softworkz committed 1 year ago

Commit 4ff90f01 parent d2259281 file · +14 −9Browse files

Unified · Split

fftools/textformat/avtextformat.c+14−9
@@ -311,24 +311,28 @@ void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t va · 310 unmodified lines
311311
312312 static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
313313 {
314− const uint8_t *p, *endp;
314+ const uint8_t *p, *endp, *srcp = (const uint8_t *)src;
315315 AVBPrint dstbuf;
316+ AVBPrint invalid_seq;
316317 int invalid_chars_nb = 0, ret = 0;
317318
319+ *dstp = NULL;
318320 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
321+ av_bprint_init(&invalid_seq, 0, AV_BPRINT_SIZE_UNLIMITED);
319322
320− endp = src + strlen(src);
321− for (p = src; *p;) {
322− uint32_t code;
323+ endp = srcp + strlen(src);
324+ for (p = srcp; *p;) {
325+ int32_t code;
323326 int invalid = 0;
324327 const uint8_t *p0 = p;
325328
326329 if (av_utf8_decode(&code, &p, endp, tctx->string_validation_utf8_flags) < 0) {
327− AVBPrint bp;
328− av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
329− bprint_bytes(&bp, p0, p-p0);
330− av_log(tctx, AV_LOG_DEBUG,
331− "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
330+
331+ av_bprint_clear(&invalid_seq);
332+
333+ bprint_bytes(&invalid_seq, p0, p - p0);
334+
335+ av_log(tctx, AV_LOG_DEBUG, "Invalid UTF-8 sequence '%s' found in string '%s'\n", invalid_seq.str, src);
332336 invalid = 1;
333337 }
334338
@@ -358,6 +362,7 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const · 23 unmodified lines
358362
359363 end:
360364 av_bprint_finalize(&dstbuf, dstp);
365+ av_bprint_finalize(&invalid_seq, NULL);
361366 return ret;
362367 }
363368

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t