diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-03-11 10:01:04 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-03-12 08:38:42 +0100 |
commit | f226854d256a382a5cc7ff08b10a0d27fbefb0fe (patch) | |
tree | 01724530659f086e0080674b185336bbb82dadbc /tests/auto/corelib/tools/qhash | |
parent | ae88dea1bea0016a124e7030a04877baa4efc2bd (diff) |
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
Pick-to: 6.0 6.1
Change-Id: Ia20440cd7bdc03cb09c77f796fb9c5b52765eac5
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qhash')
-rw-r--r-- | tests/auto/corelib/tools/qhash/tst_qhash.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 014617f8d4..079b9c6ab7 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -80,6 +80,8 @@ private slots: void hashOfHash(); void stdHash(); + + void countInEmptyHash(); }; struct IdentityTracker { @@ -1976,5 +1978,18 @@ void tst_QHash::stdHash() QVERIFY(!strings.contains("z")); } +void tst_QHash::countInEmptyHash() +{ + { + QHash<int, int> hash; + QCOMPARE(hash.count(42), 0); + } + + { + QMultiHash<int, int> hash; + QCOMPARE(hash.count(42), 0); + } +} + QTEST_APPLESS_MAIN(tst_QHash) #include "tst_qhash.moc" |