diff --git a/examples/io.c b/examples/io.c index 689e0f6098d4e3d23b86b2ece2322b4bea4a085b..c24546f54f0cfa3b294b645b6988d33f4c06b0bb 100644 --- a/examples/io.c +++ b/examples/io.c @@ -88,8 +88,13 @@ read_file(const char *name, unsigned max_size, char **contents) size = max_size; else size = 100; - - for (size = 100, done = 0; + + /* FIXME: The use of feof and ferror in this loop is a bit confused + (but I think it is still correct). We should check the return + value of fread, and call feof and/or ferror when we get a short + item count. */ + + for (done = 0; (!max_size || done < max_size) && !feof(f); size *= 2) {