[zeromq-dev] Incompatible iterator types in xrep.cpp

Martin Sustrik sustrik at 250bpm.com
Wed May 4 11:52:45 CEST 2011


Hi Tore,

> (Using latest 3.0 source : xrep.cpp - lines 98-112)
>
> void zmq::xrep_t::terminated (reader_t *pipe_)
> {
>      for (inpipes_t::iterator it = inpipes.begin (); it != inpipes.end ();
>            ++it) {
>          if (it->reader == pipe_) {
>              inpipes.erase (it);
>              if ((inpipes_t::size_type) (it - inpipes.begin ())<  current_in)
>                  current_in--;
>              if (terminating)
>                  unregister_term_ack ();
>              return;
>          }
>      }
>      zmq_assert (false);
> }
>
> I think that comparing an erased iterator isn't strictly valid.
> Erase should probably be done after decreasing current_in.
>
> To be honest, I'm not quite sure what this function does, but
> accessing iterators after erase is usually not a good idea.

You are right. The two lines should be exchanged. Would you like to 
provide the patch?

Martin



More information about the zeromq-dev mailing list