[Scummvm-devel] The semantics of reading beyond the end of a stream

Torbjörn Andersson eriktorbjorn at telia.com
Sun Sep 13 12:49:51 CEST 2009


Hi,

I was just wondering... until recently, reading an 8-, 16- or 32-bit
value completely beyond the end of a stream would return 0. This is
because the readByte()/readSByte() functions do, and the other functions
were implemented by calling readByte().

With the recent (r44027) changes this. The 16- and 32-bit functions are
implemented in terms of read(), so reading beyond the end of the stream
is undefined. The readByte() function still returns 0, but there's a
FIXME comment about removing this.

The change uncovered a crash in The 7th Guest, which is how I noticed it
in the first place. (I can't believe I've spent this much time hunting
for a bug in a game I don't even particularly like! :-)

What is the desired behaviour here? It seems a bit inconsistent that the
functions behave differently. In my opinion, either all of them should
return 0 or none of them should.

Torbjörn Andersson




More information about the Scummvm-devel mailing list