There's another check for EOF which needs to be enclosed inside the number of characters read check...
Merge pull request #4 from mandrav/master

An EOF check has slipped...