History

jbig2dec: Need to store local copy of error message.

Sebastian Rasmussen committed 6 years ago

Commit 3fd58721 parent 4b0abdb1 file · +31 −17Browse files

Unified · Split

jbig2dec.c+31−17
@@ -70,7 +70,7 @@ typedef struct { · 69 unmodified lines
7070
7171 typedef struct {
7272 int verbose;
73− const char *last_message;
73+ char *last_message;
7474 Jbig2Severity severity;
7575 char *type;
7676 long repeats;
@@ -402,9 +402,15 @@ error_callback(void *error_callback_data, const char *message, Jbig2Severity sev · 325 unmodified lines
402402 break;
403403 }
404404
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) {
408414 ret = fprintf(stderr, "jbig2dec %s last message repeated %ld times\n", state->type, state->repeats);
409415 if (ret < 0)
410416 goto printerror;
@@ -417,16 +423,19 @@ error_callback(void *error_callback_data, const char *message, Jbig2Severity sev · 6 unmodified lines
417423 if (ret < 0)
418424 goto printerror;
419425
420− state->last_message = message;
426+ state->repeats = 0;
421427 state->severity = severity;
422428 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+ }
430439 }
431440 }
432441
@@ -434,8 +443,9 @@ error_callback(void *error_callback_data, const char *message, Jbig2Severity sev · 1 unmodified line
434443
435444 printerror:
436445 fprintf(stderr, "jbig2dec WARNING could not print message\n");
437− state->last_message = NULL;
438446 state->repeats = 0;
447+ free(state->last_message);
448+ state->last_message = NULL;
439449 }
440450
441451 static void
@@ -559,6 +569,12 @@ main(int argc, char **argv) · 117 unmodified lines
559569
560570 filearg = parse_options(argc, argv, &params);
561571
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+
562578 if (params.hash)
563579 hash_init(&params);
564580
@@ -604,10 +620,6 @@ main(int argc, char **argv) · 39 unmodified lines
604620 goto cleanup;
605621 }
606622
607− error_callback_state.verbose = params.verbose;
608− error_callback_state.last_message = NULL;
609− error_callback_state.repeats = 0;
610−
611623 if (params.memory_limit == 0)
612624 allocator = NULL;
613625 else
@@ -759,6 +771,8 @@ cleanup: · 145 unmodified lines
759771 jbig2_ctx_free(ctx);
760772 if (params.output_filename)
761773 free(params.output_filename);
774+ if (error_callback_state.last_message)
775+ free(error_callback_state.last_message);
762776 if (params.hash)
763777 hash_free(&params);
764778

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