Unified · Split
| @@ -70,7 +70,7 @@ typedef struct { · 69 unmodified lines | ||
| 70 | 70 | |
| 71 | 71 | typedef struct { |
| 72 | 72 | int verbose; |
| 73 | − const char *last_message; | |
| 73 | + char *last_message; | |
| 74 | 74 | Jbig2Severity severity; |
| 75 | 75 | char *type; |
| 76 | 76 | long repeats; |
| @@ -402,9 +402,15 @@ error_callback(void *error_callback_data, const char *message, Jbig2Severity sev · 325 unmodified lines | ||
| 402 | 402 | break; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | − if (state->last_message == NULL || (state->last_message != NULL && strcmp(message, state->last_message) && state->severity == severity && state->type == type)) { | |
| 406 | − if (state->repeats > 1) | |
| 407 | − { | |
| 405 | + if (state->last_message != NULL && !strcmp(message, state->last_message) && state->severity == severity && state->type == type) { | |
| 406 | + state->repeats++; | |
| 407 | + if (state->repeats % 1000000 == 0) { | |
| 408 | + ret = fprintf(stderr, "jbig2dec %s last message repeated %ld times so far\n", state->type, state->repeats); | |
| 409 | + if (ret < 0) | |
| 410 | + goto printerror; | |
| 411 | + } | |
| 412 | + } else { | |
| 413 | + if (state->repeats > 1) { | |
| 408 | 414 | ret = fprintf(stderr, "jbig2dec %s last message repeated %ld times\n", state->type, state->repeats); |
| 409 | 415 | if (ret < 0) |
| 410 | 416 | goto printerror; |
| @@ -417,16 +423,19 @@ error_callback(void *error_callback_data, const char *message, Jbig2Severity sev · 6 unmodified lines | ||
| 417 | 423 | if (ret < 0) |
| 418 | 424 | goto printerror; |
| 419 | 425 | |
| 420 | − state->last_message = message; | |
| 426 | + state->repeats = 0; | |
| 421 | 427 | state->severity = severity; |
| 422 | 428 | state->type = type; |
| 423 | − state->repeats = 0; | |
| 424 | − } else if (state->last_message != NULL) { | |
| 425 | − state->repeats++; | |
| 426 | − if (state->repeats % 1000000 == 0) { | |
| 427 | − ret = fprintf(stderr, "jbig2dec %s last message repeated %ld times so far\n", state->type, state->repeats); | |
| 428 | − if (ret < 0) | |
| 429 | − goto printerror; | |
| 429 | + free(state->last_message); | |
| 430 | + state->last_message = NULL; | |
| 431 | + | |
| 432 | + if (message) { | |
| 433 | + state->last_message = strdup(message); | |
| 434 | + if (state->last_message == NULL) { | |
| 435 | + ret = fprintf(stderr, "jbig2dec WARNING could not duplicate message\n"); | |
| 436 | + if (ret < 0) | |
| 437 | + goto printerror; | |
| 438 | + } | |
| 430 | 439 | } |
| 431 | 440 | } |
| 432 | 441 | |
| @@ -434,8 +443,9 @@ error_callback(void *error_callback_data, const char *message, Jbig2Severity sev · 1 unmodified line | ||
| 434 | 443 | |
| 435 | 444 | printerror: |
| 436 | 445 | fprintf(stderr, "jbig2dec WARNING could not print message\n"); |
| 437 | − state->last_message = NULL; | |
| 438 | 446 | state->repeats = 0; |
| 447 | + free(state->last_message); | |
| 448 | + state->last_message = NULL; | |
| 439 | 449 | } |
| 440 | 450 | |
| 441 | 451 | static void |
| @@ -559,6 +569,12 @@ main(int argc, char **argv) · 117 unmodified lines | ||
| 559 | 569 | |
| 560 | 570 | filearg = parse_options(argc, argv, ¶ms); |
| 561 | 571 | |
| 572 | + error_callback_state.verbose = params.verbose; | |
| 573 | + error_callback_state.severity = JBIG2_SEVERITY_DEBUG; | |
| 574 | + error_callback_state.type = NULL; | |
| 575 | + error_callback_state.last_message = NULL; | |
| 576 | + error_callback_state.repeats = 0; | |
| 577 | + | |
| 562 | 578 | if (params.hash) |
| 563 | 579 | hash_init(¶ms); |
| 564 | 580 | |
| @@ -604,10 +620,6 @@ main(int argc, char **argv) · 39 unmodified lines | ||
| 604 | 620 | goto cleanup; |
| 605 | 621 | } |
| 606 | 622 | |
| 607 | − error_callback_state.verbose = params.verbose; | |
| 608 | − error_callback_state.last_message = NULL; | |
| 609 | − error_callback_state.repeats = 0; | |
| 610 | − | |
| 611 | 623 | if (params.memory_limit == 0) |
| 612 | 624 | allocator = NULL; |
| 613 | 625 | else |
| @@ -759,6 +771,8 @@ cleanup: · 145 unmodified lines | ||
| 759 | 771 | jbig2_ctx_free(ctx); |
| 760 | 772 | if (params.output_filename) |
| 761 | 773 | free(params.output_filename); |
| 774 | + if (error_callback_state.last_message) | |
| 775 | + free(error_callback_state.last_message); | |
| 762 | 776 | if (params.hash) |
| 763 | 777 | hash_free(¶ms); |
| 764 | 778 | |