When eof is set inside the for loop, we always break out of the loop.
When the bottom of the outer while(!eof) loop is encountered, that
loop will also terminated, so the false branch of "if (!eof)" should
never be taken.
This additional test seems to trigger a false positive out-of-bounds
read warning from Coverity (CID 1008693). It tries to analyze the
i == buflen, findstr != 0, and eof != 0 case and observes that i does
not get adjusted by the inner block of code. Then buf[i] is accessed,
which is past the end of the allocated buffer. It is only false
positive since eof is always zero at this point in the code.
Set eof = 1 instead of incrementing eof. An assignment by a constant
value should be a bit faster than a read-modify-write and avoids have
to worry about wrapping from non-zero back to zero.