Opened 20 years ago

Closed 20 years ago

Last modified 6 years ago

#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 fingolfin, 20 years ago

Owner: changed from fingolfin to aquadran
Summary: Bug in File classALL: Bug in File class

comment:2 by fingolfin, 20 years ago

No idea, aquadran wrote that code.

comment:3 by aquadran, 20 years ago

it's propably c&p bug, eof code is based on pre File class code.

comment:4 by sev-, 20 years ago

Owner: changed from aquadran to sev-
Resolution: fixed
Status: newclosed

comment:5 by sev-, 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 digitall, 6 years ago

Component: --Unset----Other--
Note: See TracTickets for help on using tickets.