From 341654213bfd02a448490212e3b9b0d2027dfd2f Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Thu, 11 Mar 2021 10:01:04 +0100 Subject: Fix QMultiHash::count(key) crash As QMultiHash uses a pointer for the data, nullptr dereference is a thing, so check for valid d before doing anything in count() Fixes: QTBUG-91704 Change-Id: Ia20440cd7bdc03cb09c77f796fb9c5b52765eac5 Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira (cherry picked from commit f226854d256a382a5cc7ff08b10a0d27fbefb0fe) Reviewed-by: Fabian Kosmale --- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/auto/corelib/tools/qhash/tst_qhash.cpp') diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 5389758b5f..0c3253784e 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -76,6 +76,8 @@ private slots: void badHashFunction(); void hashOfHash(); + + void countInEmptyHash(); }; struct IdentityTracker { @@ -1890,5 +1892,18 @@ void tst_QHash::hashOfHash() (void)qHash(multiHash); } +void tst_QHash::countInEmptyHash() +{ + { + QHash hash; + QCOMPARE(hash.count(42), 0); + } + + { + QMultiHash hash; + QCOMPARE(hash.count(42), 0); + } +} + QTEST_APPLESS_MAIN(tst_QHash) #include "tst_qhash.moc" -- cgit v1.2.3