From kopete-devel Sun Jun 26 19:34:05 2005 From: Richard Smith Date: Sun, 26 Jun 2005 19:34:05 +0000 To: kopete-devel Subject: [kopete-devel] Re: [PATCH] Avoiding to test on end() Message-Id: <200506262034.05344.kde () metafoo ! co ! uk> X-MARC-Message: https://marc.info/?l=kopete-devel&m=111981447931953 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