From 838edd9c48284b97dfc22cf3644bb082035a9a93 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 11 Nov 2021 11:37:22 +0100 Subject: [PATCH] Fix QMultiHash::operator== crash QMultiHash::operator== crashes when comparing two unequal objects. This patch fixes it. Pick-to: 6.2 Fixes: QTBUG-98265 Change-Id: Ibf9fef3372a2b4581843be5f25e65cc9a55ef64d Reviewed-by: Lars Knoll --- src/corelib/tools/qhash.h | 6 +++--- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 49c9ce1d41..3d92d95e62 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1323,12 +1323,12 @@ public: if (d->size != other.d->size) return false; for (auto it = other.d->begin(); it != other.d->end(); ++it) { - auto i = d->find(it.node()->key); - if (i == d->end()) + auto *n = d->findNode(it.node()->key); + if (!n) return false; Chain *e = it.node()->value; while (e) { - Chain *oe = i.node()->value; + Chain *oe = n->value; while (oe) { if (oe->value == e->value) break; diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 576a1c6107..7e297c0119 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -95,6 +95,8 @@ private slots: void fineTuningInEmptyHash(); void reserveShared(); + + void QTBUG98265(); }; struct IdentityTracker { @@ -1742,6 +1744,7 @@ void tst_QHash::qmultihash_specific() map2.insert(48, 3); QCOMPARE(map1.count(), map2.count()); QVERIFY(map1.remove(42,5)); + QVERIFY(map1 != map2); QVERIFY(map2.remove(42,5)); QVERIFY(map1 == map2); @@ -2615,5 +2618,14 @@ void tst_QHash::reserveShared() QCOMPARE(hash.capacity(), oldCap); } +void tst_QHash::QTBUG98265() +{ + QMultiHash a; + QMultiHash b; + a.insert(QUuid("3e0dfb4d-90eb-43a4-bd54-88f5b69832c1"), QByteArray()); + b.insert(QUuid("1b710ada-3dd7-432e-b7c8-e852e59f46a0"), QByteArray()); + + QVERIFY(a != b); +} QTEST_APPLESS_MAIN(tst_QHash) #include "tst_qhash.moc"