Skip to content

Commit

Permalink
fix for printing error mid line before newline was written
Browse files Browse the repository at this point in the history
  • Loading branch information
FRex committed May 31, 2022
1 parent de9fcae commit eb08c26
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion analyzepng.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ struct myruntime
int sbitbytes;
int verifycrc;
unsigned crcvar;

/* prepend \n to the error message, set to 1 when in the middle of writing a
multi part message and some operation requires more reads that might fail */
int errorneedsnewline;
};

/* named myread to not conflict with POSIX function of same name */
Expand Down Expand Up @@ -254,7 +258,7 @@ static void skip_step_int(struct myruntime * runtime, int amount)

static void error(struct myruntime * runtime, const char * errmsg)
{
fprintf(stderr, "Error: %s\n", errmsg);
fprintf(stderr, "%sError: %s\n", runtime->errorneedsnewline ? "\n" : "", errmsg);
longjmp(runtime->jumper, 1);
}

Expand Down Expand Up @@ -828,6 +832,8 @@ static int parse_png_chunk(struct myruntime * runtime)
usedbyextra = print_extra_info(runtime, len, buff + 4);
}

runtime->errorneedsnewline = 1;

if(runtime->verifycrc)
{
unsigned char buff[16 * 1024];
Expand Down Expand Up @@ -856,6 +862,7 @@ static int parse_png_chunk(struct myruntime * runtime)
if(printchunk)
printf("\n");

runtime->errorneedsnewline = 0;
++runtime->chunks;
runtime->idatchunks += isidat;
return 0 != strncmp(buff + 4, "IEND", 4);
Expand Down

0 comments on commit eb08c26

Please sign in to comment.