[zeromq-dev] [PATCH] more iterator invalidation patches

Jon Dyte jon at totient.co.uk
Mon May 9 23:59:52 CEST 2011


Martin Sustrik wrote:
> Hi Jon,
>
>> the iterators are not handled correctly when using erase on the
>> container in two places on
>> the inpipes and outpipes collections respectively.
>
> > -            inpipes.erase (it);
> > +            it = inpipes.erase (it);
>
> Unfortunately, the vector::erase function is defined as void in some 
> STL implementations.

nothing much can be done about incorrect implementations of the standard 
library other than workarounds

>
> > -            outpipes.erase (it);
> > +            outpipes.erase (it++);
>
> This doesn't solve the problem. The iterator is used *after* erasing 
> both in the original code and your patch.

as discussed on IRC and elsewhere that isnt true it++ is guaranteed to 
be executed before the erase call.

I'll look at another patch and see if it's actually buys anything in 
terms of clarity etc, because if those return calls are ever removed as
things stand the loops are broken....

Jon



More information about the zeromq-dev mailing list