Skip to content

Commit

Permalink
We can't iterate over the object we are modifying
Browse files Browse the repository at this point in the history
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.

Closes #354. Closes #355.
  • Loading branch information
glance- authored and keithw committed Dec 1, 2012
1 parent 0496a8f commit 70a7c80
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/statesync/user.cc
Expand Up @@ -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();
Expand Down

0 comments on commit 70a7c80

Please sign in to comment.