[Scummvm-devel] eof & err

Johannes Schickel lordhoto at scummvm.org
Sun Jul 12 21:40:48 CEST 2009


sunmax at libero.it wrote:
>>> That code is _before_ reading, though, so that should be ok.
>>>       
>> Correction: kyra does a couple of reads of length 0.
>>     
>
> Then in this case, since we are trying to read past the end,
> (even if I am not sure how to interpret the "length 0" case,
> btw: why are we doing this?) we should set _eof.
>   

We do a read 0 length, because the eos bit isn't set, till we try to 
read past the end of file.

> And then if err() is supposed to return true on _eof (can
> somebody confirm this?), it should return true causing
> kyra to exit.
>   

 From the docs:

    /**
     * Returns true if an I/O failure occurred.
     * This flag is never cleared automatically. In order to clear it,
     * client code has to call clearErr() explicitly.
     */

Seeing the StdioStream::err implementation it calls "ferror" to check 
for an I/O error. Maybe your backend does not implement that correctly? 
For example returns non zero on eof there?

 From my fread manpage:

       fread() does not distinguish between end-of-file and error, and 
callers  must  use  feof(3)  and  ferror(3)  to  determine  which
       occurred.

This clearly shows (so does the ferror and feof manpage) that ferror 
should not return non zero on eof.
 

>> What happens if you just remove that check?
>>     
>
>   

Nothing, but it's ugly, since in case of missing files / corrupted files 
KYRA might just crash otherwise.


>>> The specific bugged code doing a read of 0 bytes is:
>>>
>>> // eats up all the remaining data in the chunk
>>> while (!stream.eos()) {
>>>  stream.readByte();
>>> }
>>>       
>
> Correct.
>   


Actually the code is not bugged, but that's the place there the PS2 bug 
is triggered (I think). I guess I didn't make that clear. A read of size 
0 is valid.


>>> in common/iff_parser.h l293. Since SubReadStream relies on the
>>> parent streams eos, in this case a StdioStream, either 
>>> StdioStream::eos is bugged or there's a little bug in
>>> SubReadStream.
>>>       
>
> Can one of the FS / Stream gurus have a loot into that?
>   

Think wjp made it pretty clear, your backend is bugged. It works just 
fine over here on my Linux with reads of length 0. I suspect your ferror 
implementation is just bugged (see above).

// Johannes




More information about the Scummvm-devel mailing list