| @@ -93,9 +93,8 @@ static const AVClass textcontext_class = { · 92 unmodified lines |
| 93 | | 93 | |
| 94 | static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size) | 94 | static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size) |
| 95 | { | 95 | { |
| 96 | int i; | | |
| 97 | av_bprintf(bp, "0X"); | 96 | av_bprintf(bp, "0X"); |
| 98 | for (i = 0; i < ubuf_size; i++) | 97 | for (unsigned i = 0; i < ubuf_size; i++) |
| 99 | av_bprintf(bp, "%02X", ubuf[i]); | 98 | av_bprintf(bp, "%02X", ubuf[i]); |
| 100 | } | 99 | } |
| 101 | | 100 | |
| @@ -137,6 +136,8 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form · 35 unmodified lines |
| 137 | AVTextFormatContext *tctx; | 136 | AVTextFormatContext *tctx; |
| 138 | int i, ret = 0; | 137 | int i, ret = 0; |
| 139 | | 138 | |
| | 139 | av_assert0(ptctx && formatter); |
| | 140 | |
| 140 | if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) { | 141 | if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) { |
| 141 | ret = AVERROR(ENOMEM); | 142 | ret = AVERROR(ENOMEM); |
| 142 | goto fail; | 143 | goto fail; |
| @@ -215,8 +216,8 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form · 72 unmodified lines |
| 215 | | 216 | |
| 216 | /* validate replace string */ | 217 | /* validate replace string */ |
| 217 | { | 218 | { |
| 218 | const uint8_t *p = tctx->string_validation_replacement; | 219 | const uint8_t *p = (uint8_t *)tctx->string_validation_replacement; |
| 219 | const uint8_t *endp = p + strlen(p); | 220 | const uint8_t *endp = p + strlen((const char *)p); |
| 220 | while (*p) { | 221 | while (*p) { |
| 221 | const uint8_t *p0 = p; | 222 | const uint8_t *p0 = p; |
| 222 | int32_t code; | 223 | int32_t code; |
| @@ -229,6 +230,7 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form · 6 unmodified lines |
| 229 | "Invalid UTF8 sequence %s found in string validation replace '%s'\n", | 230 | "Invalid UTF8 sequence %s found in string validation replace '%s'\n", |
| 230 | bp.str, tctx->string_validation_replacement); | 231 | bp.str, tctx->string_validation_replacement); |
| 231 | return ret; | 232 | return ret; |
| | 233 | goto fail; |
| 232 | } | 234 | } |
| 233 | } | 235 | } |
| 234 | } | 236 | } |
| @@ -256,6 +258,11 @@ static const char unit_bit_per_second_str[] = "bit/s"; · 21 unmodified lines |
| 256 | | 258 | |
| 257 | void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id) | 259 | void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id) |
| 258 | { | 260 | { |
| | 261 | if (section_id < 0 || section_id >= tctx->nb_sections) { |
| | 262 | av_log(tctx, AV_LOG_ERROR, "Invalid section_id for section_header: %d\n", section_id); |
| | 263 | return; |
| | 264 | } |
| | 265 | |
| 259 | tctx->level++; | 266 | tctx->level++; |
| 260 | av_assert0(tctx->level < SECTION_MAX_NB_LEVELS); | 267 | av_assert0(tctx->level < SECTION_MAX_NB_LEVELS); |
| 261 | | 268 | |
| @@ -269,6 +276,11 @@ void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, in · 7 unmodified lines |
| 269 | | 276 | |
| 270 | void avtext_print_section_footer(AVTextFormatContext *tctx) | 277 | void avtext_print_section_footer(AVTextFormatContext *tctx) |
| 271 | { | 278 | { |
| | 279 | if (tctx->level < 0 || tctx->level >= SECTION_MAX_NB_LEVELS) { |
| | 280 | av_log(tctx, AV_LOG_ERROR, "Invalid level for section_footer: %d\n", tctx->level); |
| | 281 | return; |
| | 282 | } |
| | 283 | |
| 272 | int section_id = tctx->section[tctx->level]->id; | 284 | int section_id = tctx->section[tctx->level]->id; |
| 273 | int parent_section_id = tctx->level ? | 285 | int parent_section_id = tctx->level ? |
| 274 | tctx->section[tctx->level - 1]->id : SECTION_ID_NONE; | 286 | tctx->section[tctx->level - 1]->id : SECTION_ID_NONE; |
| @@ -285,7 +297,11 @@ void avtext_print_section_footer(AVTextFormatContext *tctx) · 10 unmodified lines |
| 285 | | 297 | |
| 286 | void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val) | 298 | void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val) |
| 287 | { | 299 | { |
| 288 | const struct AVTextFormatSection *section = tctx->section[tctx->level]; | 300 | const AVTextFormatSection *section; |
| | 301 | |
| | 302 | av_assert0(key && tctx->level >= 0 && tctx->level < SECTION_MAX_NB_LEVELS); |
| | 303 | |
| | 304 | section = tctx->section[tctx->level]; |
| 289 | | 305 | |
| 290 | if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) { | 306 | if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) { |
| 291 | tctx->formatter->print_integer(tctx, key, val); | 307 | tctx->formatter->print_integer(tctx, key, val); |
| @@ -354,17 +370,18 @@ struct unit_value { · 62 unmodified lines |
| 354 | const char *unit; | 370 | const char *unit; |
| 355 | }; | 371 | }; |
| 356 | | 372 | |
| 357 | static char *value_string(AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv) | 373 | static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv) |
| 358 | { | 374 | { |
| 359 | double vald; | 375 | double vald; |
| 360 | int64_t vali; | 376 | int64_t vali = 0; |
| 361 | int show_float = 0; | 377 | int show_float = 0; |
| 362 | | 378 | |
| 363 | if (uv.unit == unit_second_str) { | 379 | if (uv.unit == unit_second_str) { |
| 364 | vald = uv.val.d; | 380 | vald = uv.val.d; |
| 365 | show_float = 1; | 381 | show_float = 1; |
| 366 | } else { | 382 | } else { |
| 367 | vald = vali = uv.val.i; | 383 | vald = (double)uv.val.i; |
| | 384 | vali = uv.val.i; |
| 368 | } | 385 | } |
| 369 | | 386 | |
| 370 | if (uv.unit == unit_second_str && tctx->use_value_sexagesimal_format) { | 387 | if (uv.unit == unit_second_str && tctx->use_value_sexagesimal_format) { |
| @@ -383,17 +400,17 @@ static char *value_string(AVTextFormatContext *tctx, char *buf, int buf_size, st · 12 unmodified lines |
| 383 | int64_t index; | 400 | int64_t index; |
| 384 | | 401 | |
| 385 | if (uv.unit == unit_byte_str && tctx->use_byte_value_binary_prefix) { | 402 | if (uv.unit == unit_byte_str && tctx->use_byte_value_binary_prefix) { |
| 386 | index = (int64_t) (log2(vald)) / 10; | 403 | index = (int64_t)(log2(vald) / 10); |
| 387 | index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); | 404 | index = av_clip64(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); |
| 388 | vald /= si_prefixes[index].bin_val; | 405 | vald /= si_prefixes[index].bin_val; |
| 389 | prefix_string = si_prefixes[index].bin_str; | 406 | prefix_string = si_prefixes[index].bin_str; |
| 390 | } else { | 407 | } else { |
| 391 | index = (int64_t) (log10(vald)) / 3; | 408 | index = (int64_t)(log10(vald) / 3); |
| 392 | index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); | 409 | index = av_clip64(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); |
| 393 | vald /= si_prefixes[index].dec_val; | 410 | vald /= si_prefixes[index].dec_val; |
| 394 | prefix_string = si_prefixes[index].dec_str; | 411 | prefix_string = si_prefixes[index].dec_str; |
| 395 | } | 412 | } |
| 396 | vali = vald; | 413 | vali = (int64_t)vald; |
| 397 | } | 414 | } |
| 398 | | 415 | |
| 399 | if (show_float || (tctx->use_value_prefix && vald != (int64_t)vald)) | 416 | if (show_float || (tctx->use_value_prefix && vald != (int64_t)vald)) |
| @@ -421,9 +438,13 @@ void avtext_print_unit_int(AVTextFormatContext *tctx, const char *key, int value · 21 unmodified lines |
| 421 | | 438 | |
| 422 | int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags) | 439 | int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags) |
| 423 | { | 440 | { |
| 424 | const struct AVTextFormatSection *section = tctx->section[tctx->level]; | 441 | const AVTextFormatSection *section; |
| 425 | int ret = 0; | 442 | int ret = 0; |
| 426 | | 443 | |
| | 444 | av_assert0(key && val && tctx->level >= 0 && tctx->level < SECTION_MAX_NB_LEVELS); |
| | 445 | |
| | 446 | section = tctx->section[tctx->level]; |
| | 447 | |
| 427 | if (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER || | 448 | if (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER || |
| 428 | (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO | 449 | (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO |
| 429 | && (flags & AV_TEXTFORMAT_PRINT_STRING_OPTIONAL) | 450 | && (flags & AV_TEXTFORMAT_PRINT_STRING_OPTIONAL) |
| @@ -465,12 +486,11 @@ void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRationa · 35 unmodified lines |
| 465 | void avtext_print_time(AVTextFormatContext *tctx, const char *key, | 486 | void avtext_print_time(AVTextFormatContext *tctx, const char *key, |
| 466 | int64_t ts, const AVRational *time_base, int is_duration) | 487 | int64_t ts, const AVRational *time_base, int is_duration) |
| 467 | { | 488 | { |
| 468 | char buf[128]; | | |
| 469 | | | |
| 470 | if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) { | 489 | if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) { |
| 471 | avtext_print_string(tctx, key, "N/A", AV_TEXTFORMAT_PRINT_STRING_OPTIONAL); | 490 | avtext_print_string(tctx, key, "N/A", AV_TEXTFORMAT_PRINT_STRING_OPTIONAL); |
| 472 | } else { | 491 | } else { |
| 473 | double d = ts * av_q2d(*time_base); | 492 | char buf[128]; |
| | 493 | double d = av_q2d(*time_base) * ts; |
| 474 | struct unit_value uv; | 494 | struct unit_value uv; |
| 475 | uv.val.d = d; | 495 | uv.val.d = d; |
| 476 | uv.unit = unit_second_str; | 496 | uv.unit = unit_second_str; |
| @@ -491,7 +511,8 @@ void avtext_print_data(AVTextFormatContext *tctx, const char *name, · 14 unmodified lines |
| 491 | const uint8_t *data, int size) | 511 | const uint8_t *data, int size) |
| 492 | { | 512 | { |
| 493 | AVBPrint bp; | 513 | AVBPrint bp; |
| 494 | int offset = 0, l, i; | 514 | unsigned offset = 0; |
| | 515 | int l, i; |
| 495 | | 516 | |
| 496 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); | 517 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); |
| 497 | av_bprintf(&bp, "\n"); | 518 | av_bprintf(&bp, "\n"); |
| @@ -518,25 +539,29 @@ void avtext_print_data(AVTextFormatContext *tctx, const char *name, · 20 unmodified lines |
| 518 | void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, | 539 | void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, |
| 519 | const uint8_t *data, int size) | 540 | const uint8_t *data, int size) |
| 520 | { | 541 | { |
| 521 | char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 }; | 542 | char buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 }; |
| | 543 | int len; |
| 522 | | 544 | |
| 523 | if (!tctx->hash) | 545 | if (!tctx->hash) |
| 524 | return; | 546 | return; |
| 525 | | 547 | |
| 526 | av_hash_init(tctx->hash); | 548 | av_hash_init(tctx->hash); |
| 527 | av_hash_update(tctx->hash, data, size); | 549 | av_hash_update(tctx->hash, data, size); |
| 528 | snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash)); | 550 | len = snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash)); |
| 529 | p = buf + strlen(buf); | 551 | av_hash_final_hex(tctx->hash, (uint8_t *)&buf[len], (int)sizeof(buf) - len); |
| 530 | av_hash_final_hex(tctx->hash, p, buf + sizeof(buf) - p); | | |
| 531 | avtext_print_string(tctx, name, buf, 0); | 552 | avtext_print_string(tctx, name, buf, 0); |
| 532 | } | 553 | } |
| 533 | | 554 | |
| 534 | void avtext_print_integers(AVTextFormatContext *tctx, const char *name, | 555 | void avtext_print_integers(AVTextFormatContext *tctx, const char *name, |
| 535 | uint8_t *data, int size, const char *format, | 556 | uint8_t *data, int size, const char *format, |
| 536 | int columns, int bytes, int offset_add) | 557 | int columns, int bytes, int offset_add) |
| 537 | { | 558 | { |
| 538 | AVBPrint bp; | 559 | AVBPrint bp; |
| 539 | int offset = 0, l, i; | 560 | unsigned offset = 0; |
| | 561 | int l, i; |
| | 562 | |
| | 563 | if (!name || !data || !format || columns <= 0 || bytes <= 0) |
| | 564 | return; |
| 540 | | 565 | |
| 541 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); | 566 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); |
| 542 | av_bprintf(&bp, "\n"); | 567 | av_bprintf(&bp, "\n"); |
| @@ -602,12 +627,15 @@ int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *w · 59 unmodified lines |
| 602 | AVTextWriterContext *wctx; | 627 | AVTextWriterContext *wctx; |
| 603 | int ret = 0; | 628 | int ret = 0; |
| 604 | | 629 | |
| 605 | if (!(wctx = av_mallocz(sizeof(AVTextWriterContext)))) { | 630 | if (!pwctx || !writer) |
| | 631 | return AVERROR(EINVAL); |
| | 632 | |
| | 633 | if (!((wctx = av_mallocz(sizeof(AVTextWriterContext))))) { |
| 606 | ret = AVERROR(ENOMEM); | 634 | ret = AVERROR(ENOMEM); |
| 607 | goto fail; | 635 | goto fail; |
| 608 | } | 636 | } |
| 609 | | 637 | |
| 610 | if (!(wctx->priv = av_mallocz(writer->priv_size))) { | 638 | if (writer->priv_size && !((wctx->priv = av_mallocz(writer->priv_size)))) { |
| 611 | ret = AVERROR(ENOMEM); | 639 | ret = AVERROR(ENOMEM); |
| 612 | goto fail; | 640 | goto fail; |
| 613 | } | 641 | } |