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

List:       kopete-devel
Subject:    [kopete-devel] Re: [PATCH] Avoiding to test on end()
From:       Richard Smith <kde () metafoo ! co ! uk>
Date:       2005-06-26 19:34:05
Message-ID: 200506262034.05344.kde () metafoo ! co ! uk
[Download RAW message or body]

On Sunday 26 June 2005 20:27, Grzegorz Piotr Jaskiewicz wrote:
> On Saturday 25 June 2005 19:43, Michel Hermier wrote:
> > Hi,
> > This patch avoids to loop until reaching end(); while decrementing the
> > iterator. The current code is wrong for 2 reasons:
> > - decrementing to the begin of the list doesn't return the same value as
> > end(); - decrementing to the iterator at the first place, is undefined
> > (see http://doc.trolltech.com/3.3/qmapiterator.html#operator-- )
> > So this provoke an invalid read (potential crash).
> >
> > Comments? commit?
>
> I'm sorry, but besides not using extra iterator this patch don't do
> anything good. Makes code less readable.
> checking against end() everytime is good, you won't run into race cond,
> when other thread, or something you just called remove/added few elements
> to your list.

The current code is *broken*. The QMapIterator documentation says:

"Decrementing the iterator returned by begin() causes undefined results."

That is what the patch fixes. The code is assuming that --begin() == end().
-- 
Thanks,
Richard
_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

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