Closed philpem closed 9 years ago
On quick inspection, there's a marked difference between the encode() and decode() functions in heatshrink.c. It looks like reaching the end of the file might cause the decode() function to exit without properly flushing the decompression buffer (sink_read).
Adding O_BINARY
to the open()
parameters in handle_open()
fixes this nicely, per sjaeckel's PR #4 (commit e9c766b01876100e6829f44556da3f939f99218b).
An easy way to deal with O_BINARY not being defined on Linux would be to #ifdef
it at the top of heatshrink.c, and define it as zero if it isn't defined (the platform doesn't differentiate between binary and text files). ORing something with zero obviously has no effect. That saves a bunch of ifdefs and the creation of macros.
If I were to clean up sjaeckel's fixes to apply to current master/tip and submit a PR, would this likely be accepted?
Yes. I may get to it myself today first, though. I'm pretty sure I know what needs to be done to fix it, and will have access to a MinGW environment to test it.
It definitely has to do with binary/non-binary file IO on Windows.
I didn't get to it today and am likely to be busy with things through the holidays, but if you make the necessary changes I'd be happy to merge them. Otherwise I'll get to it soon, this has sat open for too long. :|
After patching Heatshrink with the changes in #7 and building with MinGW (gcc 4.7.2), a valid "heatshrink.exe" executable is produced, but this binary fails to decompress data correctly.
It appears that the decode step is only processing the first block of data in the file.
Interestingly the byte counts in verbose mode are wrong too: