0

I'm recovering all 50 JPEG images, but still failing check50 with the message: "output not valid ASCII text."

Not sure if this might have something to do with it, but for some reason, my buffer[0] was being overwritten/changed to 0x00, so I slammed back in 0xff just before writing to the outfile.

I've looked at the output in hex and it seems fine to me. Any suggestions?

0

If you find that your buffer[0] is being overwritten with 0x00, you have a memory issue. Did you declare outfile_name large enough to hold all 8 chars in the string "000.jpg"? If not, and you declared it with 7 bytes, the final nul char added by sprintf (to signify the end of the string) will simply go into the next slot in memory. And that slot happens to be buffer[0].

Be sure your variable is long enough.

1
  • That's gotta be it! I declared my filename with 7 bytes. Thank you!
    – M. Stange
    Feb 5 '19 at 2:41
0

Well, I'm not sure exactly how I handled it, but now I'm passing the check. I had imported stdbool.h to use bool for the jpg_found flag and I just switched it to a zero-or-one int. I also changed instances of hard-coded 512 to a #define global variable.

I still don't know why the first byte of each buffer was being overwritten to 0x00 after assigning an outfile name with sprintf

// buffer[0]: 0xff
sprintf(outfile_name, "%03i.jpg", outfile_count);
// buffer[0]: 0x00

Everything else seems to make sense and the program works. I just had to reassign buffer[0] = 0xff.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .