From fa6bf46d76a69b8f1b03145a5e3d643d541ce353 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 5 Oct 2018 08:06:22 +0900 Subject: Room: fix a blunder leading to accessing data after move --- lib/room.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/room.cpp b/lib/room.cpp index 2253c636..c6d63ce7 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1685,10 +1685,13 @@ void Room::Private::addNewMessageEvents(RoomEvents&& events) } emit q->pendingEventMerged(); } + // Events merged and transferred from `events` to `timeline` now. + const auto from = timeline.cend() - totalInserted; + if (q->supportsCalls()) - for (const auto& evt: RoomEventsRange(events.begin(), newEnd)) - if (evt->isCallEvent()) - emit q->callEvent(q, weakPtrCast(evt)); + for (auto it = from; it != timeline.cend(); ++it) + if (auto* evt = it->viewAs()) + emit q->callEvent(q, evt); if (totalInserted > 0) { @@ -1696,7 +1699,6 @@ void Room::Private::addNewMessageEvents(RoomEvents&& events) << "Room" << displayname << "received" << totalInserted << "new events; the last event is now" << timeline.back(); - const auto from = timeline.cend() - totalInserted; // The first event in the just-added batch (referred to by `from`) // defines whose read marker can possibly be promoted any further over // the same author's events newly arrived. Others will need explicit -- cgit v1.2.3