[Scummvm-devel] eof & err

Willem Jan Palenstijn wjp at usecode.org
Sun Jul 12 21:09:17 CEST 2009


On Sun, Jul 12, 2009 at 09:06:11PM +0200, sunmax at libero.it wrote:
> Hi Willem!
> 
> > > if (_filePos >= _fileSize) {
> > > _eof = true;
> > > ...
> 
> > That code is _before_ reading, though, so that should be ok.
> 
> Yes.
> 
> Unless you immediately after check for eof (like ->err() does),
> cause in this case you will always get "true".
> 
> What's going on is:
> 
> [ common/iff_container.h ]
> 
>  - parse(...) does:
> 
>    while (!stream.eos()) {
>        stream.readByte();
>    }
> 
> a) until eos() is false it will keep reading
> 
> b) eos() becomes true when stream.readByte tries to read past
>    the last byte, so now both _eof and eos() will be true
> 
>    (see the snippet you quoted)

You're missing a step here. The variable stream is a SubReadStream of
_input, and the engine checks the eos() flag for _input.

The last stream.readByte() that triggers the eos() should _only_ trigger
an eos() for stream, and not for _input. This is because
SubReadStream::read() truncates the read internally to 0 bytes and then
calls _input->read(ptr, 0). On the PS2, this then triggers the eos flag
because of the check you gave.


-Willem Jan




More information about the Scummvm-devel mailing list