[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: qt-copy/src/xml
From:       Thiago Macieira <thiago.macieira () trolltech ! com>
Date:       2006-04-07 22:45:40
Message-ID: 200604080045.50511.thiago.macieira () trolltech ! com
[Download RAW message or body]


Matt Rogers wrote:
>On Friday 07 April 2006 09:26, you wrote:
>> On Friday, 7. April 2006 15:55, Matt Rogers wrote:
>> > > +    if (!impl || !impl->parent()->isElement())
>> >
>> > that if statement is still wrong. it should probably be
>> >
>> > if ( !impl || ( impl && !impl->parent()->isElement() ) )
>>
>> hmm, I could understand if you check for impl->parent() first before
>> dereferencing it (though I don't think that can happen), but the other
>> check is superfluent since logical operators are short-circuit
>> evaluated.
>
>except that you're doing an logical or which means even though you check
> for impl != 0 the !impl->parent()->isElement() could still crash if
> impl is 0. --

It's the other way around. If it were a bitwise or, it could crash, since 
both sides would be evaluated.

In this case, if impl == 0, the right-hand side of the || operator isn't 
evaluated because the operation is true already.

Writing this is really common:
  if (!p || !*p)
    return error;

-- 
Thiago José Macieira - thiago.macieira AT trolltech.com
Trolltech AS - Sandakerveien 116, NO-0402 Oslo, Norway

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic