diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-16 10:07:20 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-03-25 11:33:23 +0100 |
commit | 7b5e4b6944a85966a9db3f5eac7dba4695024b00 (patch) | |
tree | a82a08394535fb26883c4a3031b10f598847014c | |
parent | c269d8f0862fd2c581d57584e8d7e2493f387ee7 (diff) |
Don't call QSet::erase() on an end iterator
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 <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 4 | ||||
-rw-r--r-- | 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<QPersistentModelIndexData *>::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); } } |