[Scummvm-devel] incorrect use of stream functions

Max Horn max at quendi.de
Wed Sep 2 17:20:20 CEST 2009


Am 16.08.2009 um 17:49 schrieb Norbert Lange:

> Am 15.08.2009, 17:40 Uhr, schrieb Johannes Schickel <lordhoto at scummvm.org 
> >:
>
>> Norbert Lange wrote:
>>> So there are 3 ways to deal with that:
>>> *) update the comments and make sure streams behave the defined way.
>>>
>>
>> Actually that sounds wrong. It makes IMHO no sense to change the  
>> defined
>> behavior of certain code, just because some code violates the  
>> currently
>> defined behavior.
>>
>>> *) the code that depends on Stream::readXX returning 0 for eos is  
>>> surely
>>> reading character-streams, so keep the Stream::readXX returnin  
>>> undefined
>>> values on eos, and define a function analog to C`s getchar() which
>>> returns
>>> -1 in case of error. And make the illbehaving code use that instead.
>>>
>>
>> That sounds fine, but of course we could just change the XMLParser  
>> code
>> to use Stream::err and Stream::eos instead of checking the return  
>> value.
>
> or use the Stream::read which additionally reports back if the  
> requested
> byte really got read in 1 single functioncall.
>
> I agree that fixing the code which incorrectly uses the streams  
> would be
> the best way to go,
> but the problem here is detecting all code which has to be changed.
> I found the XMLParser easily because its run everytime ScummVM  
> starts, but
> what about code hidden in engines thats only called under certain
> conditions?

Who knows... but my hope would be that it's not much or even none. If  
not, we'll discover those places over time -- after all, this is just  
a special case of the problem of "detecting all code that contains a  
bug" ;). In the meantime, that shouldn't stop us from correcting code  
that we already know is incorrect :).

Cheers,
Max




More information about the Scummvm-devel mailing list