From 70a7c8024a3b14ebef257ec6a3d94f4f545fe834 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Fri, 30 Nov 2012 12:09:53 +0100 Subject: [PATCH] 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. Closes #354. Closes #355. --- src/statesync/user.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/statesync/user.cc b/src/statesync/user.cc index 1303eed..67cac17 100644 --- a/src/statesync/user.cc +++ b/src/statesync/user.cc @@ -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::const_iterator i = prefix->actions.begin(); i != prefix->actions.end(); i++ ) { + assert( this != prefix ); assert( !actions.empty() ); assert( *i == actions.front() ); actions.pop_front();