From e40179f641a619115aad784a7dd6d5924d01b57f Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Wed, 30 Aug 2023 00:20:47 +0200 Subject: [PATCH] Don't load data from invalid indices in MessageFilterModel --- src/models/messagefiltermodel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/models/messagefiltermodel.cpp b/src/models/messagefiltermodel.cpp index 0970dbd17..10dba604d 100644 --- a/src/models/messagefiltermodel.cpp +++ b/src/models/messagefiltermodel.cpp @@ -54,8 +54,9 @@ bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour // Don't show state events that are not the first in a consecutive group on the // same day as they will be grouped as a single delegate. const bool notLastRow = sourceRow < sourceModel()->rowCount() - 1; - const bool previousEventIsState = - sourceModel()->data(sourceModel()->index(sourceRow + 1, 0), MessageEventModel::DelegateTypeRole) == MessageEventModel::DelegateType::State; + const bool previousEventIsState = notLastRow + ? sourceModel()->data(sourceModel()->index(sourceRow + 1, 0), MessageEventModel::DelegateTypeRole) == MessageEventModel::DelegateType::State + : false; const bool newDay = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageEventModel::ShowSectionRole).toBool(); if (eventType == MessageEventModel::State && notLastRow && previousEventIsState && !newDay) { return false;