Permalink
Browse files

We can't iterate over the object we are modifying

If subtract is called on itself, prefix and this is the same and the
iterator is invalid after modifying the underlaying object.

Instead just clear everyting.
  • Loading branch information...
1 parent 0496a8f commit 1fad5a476e99eab61e5923bff934a95e8a5aef5b @glance- committed Nov 30, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/statesync/user.cc
View
@@ -43,9 +43,15 @@ using namespace ClientBuffers;
void UserStream::subtract( const UserStream *prefix )
{
+ // if we are subtracting ourself from ourself, just clear the deque
+ if ( this == prefix ) {
+ actions.clear();
+ return;
+ }
for ( deque<UserEvent>::const_iterator i = prefix->actions.begin();
i != prefix->actions.end();
i++ ) {
+ assert( this != prefix );
assert( !actions.empty() );
assert( *i == actions.front() );
actions.pop_front();

0 comments on commit 1fad5a4

Please sign in to comment.