From 084b89f3dcccdd068c975ca88a2b70c13de08355 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 20 Feb 2023 19:00:54 +0000 Subject: [PATCH] Fix two null pointer dereferences --- src/models/messageeventmodel.cpp | 3 +++ src/models/roomlistmodel.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 1279be9a0..e854d8ff2 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -975,6 +975,9 @@ QVariant MessageEventModel::getLatestMessageFromIndex(const int baseline) for (auto it = timelineBottom; it != limit; ++it) { auto evt = it->event(); auto e = eventCast(evt); + if (!e) { + continue; + } auto content = (*it)->contentJson(); diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index d936f3276..6ccff64fb 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -229,10 +229,13 @@ void RoomListModel::handleNotifications() continue; } oldNotifications += notification["event"].toObject()["event_id"].toString(); + auto room = m_connection->room(notification["room_id"].toString()); + auto currentRoom = RoomManager::instance().currentRoom(); + bool roomIsActive = currentRoom && room->id() == currentRoom->id(); // If room exists, room is NOT active OR the application is NOT active, show notification - if (room && !(room->id() == RoomManager::instance().currentRoom()->id() && QGuiApplication::applicationState() == Qt::ApplicationActive)) { + if (room && !(roomIsActive && QGuiApplication::applicationState() == Qt::ApplicationActive)) { // The room might have been deleted (for example rejected invitation). auto sender = room->user(notification["event"].toObject()["sender"].toString());