diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-10-05 08:06:22 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-10-05 08:06:22 +0900 |
commit | fa6bf46d76a69b8f1b03145a5e3d643d541ce353 (patch) | |
tree | 137498e70ef51fe90eb9da4825c3cc79b44e5fb1 | |
parent | cb33c0a0498628ded34a5c9719d6807047a8b2cd (diff) | |
download | libquotient-fa6bf46d76a69b8f1b03145a5e3d643d541ce353.tar.gz libquotient-fa6bf46d76a69b8f1b03145a5e3d643d541ce353.zip |
Room: fix a blunder leading to accessing data after move
-rw-r--r-- | lib/room.cpp | 10 |
1 files 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<CallEventBase>(evt)); + for (auto it = from; it != timeline.cend(); ++it) + if (auto* evt = it->viewAs<CallEventBase>()) + 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 |