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
311 311
312static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)312static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
313{313{
314 const uint8_t *p, *endp;314 const uint8_t *p, *endp, *srcp = (const uint8_t *)src;
315 AVBPrint dstbuf;315 AVBPrint dstbuf;
316 AVBPrint invalid_seq;
316 int invalid_chars_nb = 0, ret = 0;317 int invalid_chars_nb = 0, ret = 0;
317 318
319 *dstp = NULL;
318 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);320 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
321 av_bprint_init(&invalid_seq, 0, AV_BPRINT_SIZE_UNLIMITED);
319 322
320 endp = src + strlen(src);323 endp = srcp + strlen(src);
321 for (p = src; *p;) {324 for (p = srcp; *p;) {
322 uint32_t code;325 int32_t code;
323 int invalid = 0;326 int invalid = 0;
324 const uint8_t *p0 = p;327 const uint8_t *p0 = p;
325 328
326 if (av_utf8_decode(&code, &p, endp, tctx->string_validation_utf8_flags) < 0) {329 if (av_utf8_decode(&code, &p, endp, tctx->string_validation_utf8_flags) < 0) {
327 AVBPrint bp;330
328 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);331 av_bprint_clear(&invalid_seq);
329 bprint_bytes(&bp, p0, p-p0);332
330 av_log(tctx, AV_LOG_DEBUG,333 bprint_bytes(&invalid_seq, p0, p - p0);
331 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);334
335 av_log(tctx, AV_LOG_DEBUG, "Invalid UTF-8 sequence '%s' found in string '%s'\n", invalid_seq.str, src);
332 invalid = 1;336 invalid = 1;
333 }337 }
334 338
@@ -358,6 +362,7 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const · 23 unmodified lines
358 362
359end:363end:
360 av_bprint_finalize(&dstbuf, dstp);364 av_bprint_finalize(&dstbuf, dstp);
365 av_bprint_finalize(&invalid_seq, NULL);
361 return ret;366 return ret;
362}367}
363 368

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