| @@ -93,9 +93,8 @@ static const AVClass textcontext_class = { · 92 unmodified lines |
| 93 | 93 | |
| 94 | 94 | static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size) |
| 95 | 95 | { |
| 96 | | − int i; |
| 97 | 96 | av_bprintf(bp, "0X"); |
| 98 | | − for (i = 0; i < ubuf_size; i++) |
| 97 | + for (unsigned i = 0; i < ubuf_size; i++) |
| 99 | 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 | 136 | AVTextFormatContext *tctx; |
| 138 | 137 | int i, ret = 0; |
| 139 | 138 | |
| 139 | + av_assert0(ptctx && formatter); |
| 140 | + |
| 140 | 141 | if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) { |
| 141 | 142 | ret = AVERROR(ENOMEM); |
| 142 | 143 | goto fail; |
| @@ -215,8 +216,8 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form · 72 unmodified lines |
| 215 | 216 | |
| 216 | 217 | /* validate replace string */ |
| 217 | 218 | { |
| 218 | | − const uint8_t *p = tctx->string_validation_replacement; |
| 219 | | − const uint8_t *endp = p + strlen(p); |
| 219 | + const uint8_t *p = (uint8_t *)tctx->string_validation_replacement; |
| 220 | + const uint8_t *endp = p + strlen((const char *)p); |
| 220 | 221 | while (*p) { |
| 221 | 222 | const uint8_t *p0 = p; |
| 222 | 223 | int32_t code; |
| @@ -229,6 +230,7 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form · 6 unmodified lines |
| 229 | 230 | "Invalid UTF8 sequence %s found in string validation replace '%s'\n", |
| 230 | 231 | bp.str, tctx->string_validation_replacement); |
| 231 | 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 | 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 | 266 | tctx->level++; |
| 260 | 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 | 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 | 284 | int section_id = tctx->section[tctx->level]->id; |
| 273 | 285 | int parent_section_id = tctx->level ? |
| 274 | 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 | 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 | 306 | if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) { |
| 291 | 307 | tctx->formatter->print_integer(tctx, key, val); |
| @@ -354,17 +370,18 @@ struct unit_value { · 62 unmodified lines |
| 354 | 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 | 375 | double vald; |
| 360 | | − int64_t vali; |
| 376 | + int64_t vali = 0; |
| 361 | 377 | int show_float = 0; |
| 362 | 378 | |
| 363 | 379 | if (uv.unit == unit_second_str) { |
| 364 | 380 | vald = uv.val.d; |
| 365 | 381 | show_float = 1; |
| 366 | 382 | } else { |
| 367 | | − vald = vali = uv.val.i; |
| 383 | + vald = (double)uv.val.i; |
| 384 | + vali = uv.val.i; |
| 368 | 385 | } |
| 369 | 386 | |
| 370 | 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 | 400 | int64_t index; |
| 384 | 401 | |
| 385 | 402 | if (uv.unit == unit_byte_str && tctx->use_byte_value_binary_prefix) { |
| 386 | | − index = (int64_t) (log2(vald)) / 10; |
| 387 | | − index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); |
| 403 | + index = (int64_t)(log2(vald) / 10); |
| 404 | + index = av_clip64(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); |
| 388 | 405 | vald /= si_prefixes[index].bin_val; |
| 389 | 406 | prefix_string = si_prefixes[index].bin_str; |
| 390 | 407 | } else { |
| 391 | | − index = (int64_t) (log10(vald)) / 3; |
| 392 | | − index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); |
| 408 | + index = (int64_t)(log10(vald) / 3); |
| 409 | + index = av_clip64(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1); |
| 393 | 410 | vald /= si_prefixes[index].dec_val; |
| 394 | 411 | prefix_string = si_prefixes[index].dec_str; |
| 395 | 412 | } |
| 396 | | − vali = vald; |
| 413 | + vali = (int64_t)vald; |
| 397 | 414 | } |
| 398 | 415 | |
| 399 | 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 | 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 | 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 | 448 | if (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER || |
| 428 | 449 | (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO |
| 429 | 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 | 486 | void avtext_print_time(AVTextFormatContext *tctx, const char *key, |
| 466 | 487 | int64_t ts, const AVRational *time_base, int is_duration) |
| 467 | 488 | { |
| 468 | | − char buf[128]; |
| 469 | | − |
| 470 | 489 | if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) { |
| 471 | 490 | avtext_print_string(tctx, key, "N/A", AV_TEXTFORMAT_PRINT_STRING_OPTIONAL); |
| 472 | 491 | } else { |
| 473 | | − double d = ts * av_q2d(*time_base); |
| 492 | + char buf[128]; |
| 493 | + double d = av_q2d(*time_base) * ts; |
| 474 | 494 | struct unit_value uv; |
| 475 | 495 | uv.val.d = d; |
| 476 | 496 | uv.unit = unit_second_str; |
| @@ -491,7 +511,8 @@ void avtext_print_data(AVTextFormatContext *tctx, const char *name, · 14 unmodified lines |
| 491 | 511 | const uint8_t *data, int size) |
| 492 | 512 | { |
| 493 | 513 | AVBPrint bp; |
| 494 | | − int offset = 0, l, i; |
| 514 | + unsigned offset = 0; |
| 515 | + int l, i; |
| 495 | 516 | |
| 496 | 517 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); |
| 497 | 518 | av_bprintf(&bp, "\n"); |
| @@ -518,25 +539,29 @@ void avtext_print_data(AVTextFormatContext *tctx, const char *name, · 20 unmodified lines |
| 518 | 539 | void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, |
| 519 | 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 | 545 | if (!tctx->hash) |
| 524 | 546 | return; |
| 525 | 547 | |
| 526 | 548 | av_hash_init(tctx->hash); |
| 527 | 549 | av_hash_update(tctx->hash, data, size); |
| 528 | | − snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash)); |
| 529 | | − p = buf + strlen(buf); |
| 530 | | − av_hash_final_hex(tctx->hash, p, buf + sizeof(buf) - p); |
| 550 | + len = snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash)); |
| 551 | + av_hash_final_hex(tctx->hash, (uint8_t *)&buf[len], (int)sizeof(buf) - len); |
| 531 | 552 | avtext_print_string(tctx, name, buf, 0); |
| 532 | 553 | } |
| 533 | 554 | |
| 534 | 555 | void avtext_print_integers(AVTextFormatContext *tctx, const char *name, |
| 535 | | − uint8_t *data, int size, const char *format, |
| 536 | | − int columns, int bytes, int offset_add) |
| 556 | + uint8_t *data, int size, const char *format, |
| 557 | + int columns, int bytes, int offset_add) |
| 537 | 558 | { |
| 538 | 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 | 566 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); |
| 542 | 567 | av_bprintf(&bp, "\n"); |
| @@ -602,12 +627,15 @@ int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *w · 59 unmodified lines |
| 602 | 627 | AVTextWriterContext *wctx; |
| 603 | 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 | 634 | ret = AVERROR(ENOMEM); |
| 607 | 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 | 639 | ret = AVERROR(ENOMEM); |
| 612 | 640 | goto fail; |
| 613 | 641 | } |