Addin exceptions in SvStream

Norbert Thiebaud nthiebaud at gmail.com
Mon Dec 10 15:38:34 PST 2012


On Mon, Dec 10, 2012 at 3:41 PM, Michael Meeks <michael.meeks at suse.com> wrote:
> Hi Marc,
>
> On Mon, 2012-12-10 at 10:27 -0500, Marc-André Laverdière wrote:
>> I am doing some proactive hardening of the image filters these days,
>> and I have to say that there is a lot of code like this:
>>
>> *stream >> meh;
>
>         Which is IMHO intrinsically broken; I'd prefer to see that as:
>
>         meh = stream.ReadInt32();
>
>         Where we default to zero for end-of stream and bad streams - rather
> than uninitialized variables. Not only does it get rid of the fragile
> operator overload, make the code clearer by having the type information
> at the call-site etc. It also avoids using exceptions ;-)
>
>> if (! stream->good())
>>   return sal_False;
>>
>> It is very cluttered to do this for _every_ read.
>
>         Agreed - so people don't and un-intialized data creeps in.

Am I thinking of something else or the current syntax is:

if( ! (*stream>>meh))
{
  /* error */
}

or

bRes = sal_False
bRes |= !(*stream >> meh );
bRes |=!(*stream>> bar);
...

return bRes

iow the >> operator return a boolean that indicate the sucess or
failure of the >> operation...

Norbert


More information about the LibreOffice mailing list