From 7b5e4b6944a85966a9db3f5eac7dba4695024b00 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 16 Mar 2020 10:07:20 +0100 Subject: [PATCH] Don't call QSet::erase() on an end iterator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hash.erase(hash.constFind()) is bound to crash if the hash doesn't contain the item we're looking for. Change-Id: Icbefca87b0258970373ec55d5dc113e6ab39c5f0 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/itemmodels/qabstractitemmodel.cpp | 4 +++- src/gui/itemmodels/qstandarditemmodel.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index addeeafd45..41bdaa2ac5 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -951,7 +951,9 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, for (QVector::const_iterator it = persistent_invalidated.constBegin(); it != persistent_invalidated.constEnd(); ++it) { QPersistentModelIndexData *data = *it; - persistent.indexes.erase(persistent.indexes.constFind(data->index)); + auto index = persistent.indexes.constFind(data->index); + if (index != persistent.indexes.constEnd()) + persistent.indexes.erase(index); data->index = QModelIndex(); } } diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index fc9424763e..d0325a7f9e 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -3150,7 +3150,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const for (int i = 0; i < childList.count(); ++i) { QStandardItem *chi = childList.at(i); if (chi) { - itemsSet.erase(itemsSet.constFind(chi)); + itemsSet.remove(chi); stack.push(chi); } }