Ticket #66 (closed defect)

Opened 8 years ago

Last modified 8 years ago

wxInputStream::Eof() returns TRUE too early sometimes (+fix)

Reported by: kgeza Owned by: vadz
Priority: normal Milestone:
Component: Version:
Keywords: Cc: kgeza, vadz
Blocked By: Patch: no
Blocking:

Description

In the summary,
- 'too early' means that it returns TRUE when there is still one character to read.
- 'sometimes' means: when using wxFile (or wxFileInputStream).

Since it checks for EOF by reading one character, it checks for EOF in a position one character later than where we are. This does not cause a problem if the stream returns EOF only after reading through the whole file, but it does in case of wxFile, which sets the EOF error flag as soon as it read the last character.

This is solved if we never return TRUE as long as we could read a character - in which case we are certain not yet at the end of the steam.

A remark: either this function should not be 'const', as it changes the object properties (m_lastcount, m_lasterror), or (if it ought to be const) these should be restored after reading.

Here is a fix to the problem: (the change is in the 'if' condition):


bool wxInputStream::Eof() const
{

wxInputStream *self = (wxInputStream *)this; // const_cast

char c;
self->Read(&c, 1);
if ( self->LastRead() == 0 && GetLastError() == wxSTREAM_EOF )
{

return TRUE;

}

self->Ungetch(c);

return FALSE;

}

Change History

Changed 8 years ago by vadz

fixed in the main cvs trunk

Note: See TracTickets for help on using tickets.