diff --git a/calendaring/event.cpp b/calendaring/event.cpp --- a/calendaring/event.cpp +++ b/calendaring/event.cpp @@ -76,17 +76,22 @@ void Event::delegate(const std::vector< Attendee >& delegators, const std::vector< Attendee >& delegatees) { - //First build a list of attendee references, and insert any missing attendees - std::vector delegateesRef; + //First insert any missing attendees foreach(const Attendee &a, delegatees) { - if (Attendee *attendee = getAttendee(a.contact())) { - delegateesRef.push_back(attendee); - } else { + if (!getAttendee(a.contact())) { d->attendees.push_back(a); - delegateesRef.push_back(&d->attendees.back()); } } + //Build a list of attendee references + //These are pointers into d->attendees, so we MUST NOT modify that vector after this point! + std::vector delegateesRef; + foreach(const Attendee &a, delegatees) { + Attendee *attendee = getAttendee(a.contact()); + Q_ASSERT(attendee); + delegateesRef.push_back(attendee); + } + std::vector delegatorsRef; foreach(const Attendee& a, delegators) { if (Attendee *attendee = getAttendee(a.contact())) {