On Feb 3, 2010, at 10:33 PM, Jim Meyering wrote: > I may have encountered this already > when I was trying to create a compressed file > of size one smaller than gzip's internal buffer size. > It appeared to be impossible.
Jim, It's certainly possible to do that. For example: $ dd ibs=1 count=32744 < /dev/random 2> /dev/null | gzip | tee 32km1.gz | wc -c 32767 (It's unlikely but possible for you to get random data that is slightly compressible and end up with a different number. If that happens, just try again.) The reason that the "if (imagic1 != EOF)" before the "inptr--;" doesn't cure any realizable bug is sort of accidental. If imagic1 is EOF, that means that a routine was called to try to load more data into the input buffer and failed, leaving insize set to zero. Then there is no value of inptr that satisfies inptr < insize, since inptr is unsigned. So it doesn't even matter what inptr is at that point. I am leaving the "if (imagic1 != EOF)" there anyway, since without it it takes a fair bit of code inspection to determine that its absence is not a bug. Mark