#1807 closed defect (fixed)
ALL: Bug in File class
Reported by: | sev- | Owned by: | sev- |
---|---|---|---|
Priority: | high | Component: | --Other-- |
Version: | Keywords: | ||
Cc: | Game: |
Description
There is a bug in file class which prevents eof() method from working.
As I don't understand reason for particular code line, I post it here, though I suspect it's some kind of copy'n'paste error.
The problem is in this chunk:
real_len = fread(ptr2, 1, len, _handle); if (real_len < len) { clearerr(_handle); // <- clears eof status _ioFailed = true; }
line with comment on it prevents eof() from reporting. And simple loop like this:
File in; in.open("blah"); while(!in.eof()) { in.read(&buf, 1); }
will never end.
Same thing is in write() method, which may trigger similiar bug as well. What's the reason of clearing error of _handle? Could that be removed? If it has to be there, then something like this should be added:
if (real_len < len) { _eof = feof(_handle) != 0; clearerr(_handle); _ioFailed = true; }
and then remove that _eof in eof() method.
Ticket imported from: #1048129. Ticket imported from: bugs/1807.
Change History (6)
comment:1 by , 20 years ago
Owner: | changed from | to
---|---|
Summary: | Bug in File class → ALL: Bug in File class |
comment:2 by , 20 years ago
comment:4 by , 20 years ago
Owner: | changed from | to
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:5 by , 20 years ago
So I removed it in CVS. From clearerr() manpage:
The function clearerr() clears the end-of-file and error indicators for the stream pointed to by stream.
Why this was used in the class is not clear, though I left one such instance in seek() method.
comment:6 by , 6 years ago
Component: | --Unset-- → --Other-- |
---|
No idea, aquadran wrote that code.