John Levon wrote:

> On Tue, Feb 25, 2003 at 11:33:07AM +0000, Angus Leeming wrote:
> 
>> > -                       ListType::iterator prev = it;
>> > -                       --prev;
>> >                         forkedCalls.erase(it);
>> > -                       it = prev;
>>
>> I don't see the bug. You return to the start of the list, I move to the
>> next itme in the list. The 'prev' stuff is safe if ugly, as I understand
>> list.
> 
> it = forkedCalls.erase(it);

No good I'm afraid. This sets it == to the next element in the list so the 
subsequent ++it in the for(; it != end; ++it) buggers things up.

I guess we could have
        while (it != end) {
                if (remove_it) {
                        it = forkedCalls.erase(it);
                        actCall->emitSignal();
                        delete actCall;
                } else {
                        ++it;
                }
        }
That seems pretty clear.

      iterator
      erase(iterator __position)
      {
        _List_node_base* __next_node = __position._M_node->_M_next;
        _List_node_base* __prev_node = __position._M_node->_M_prev;
        _Node* __n = static_cast<_Node*>(__position._M_node);
        __prev_node->_M_next = __next_node;
        __next_node->_M_prev = __prev_node;
        _Destroy(&__n->_M_data);
        _M_put_node(__n);
        return iterator(static_cast<_Node*>(__next_node));
      }


-- 
Angus

Reply via email to