diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2021-10-26 13:34:38 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2021-10-26 21:56:31 +0200 |
commit | 323b97ccaea7b9442fa1bcb01514e0c5a4a97fdc (patch) | |
tree | 3c1d4bae88125c1294c3f71736ce93cb64869bb3 /tests/auto/corelib/tools | |
parent | e3f05981cbeb0b7721f960ef88effa77be2af5ce (diff) |
QHash: avoid crashing when reserving on a shared hash
Pick-to: 6.2
Change-Id: I21ad13fa223bd5a2c61112e790965093a2750268
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qhash/tst_qhash.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 3c873d093e..576a1c6107 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -93,6 +93,8 @@ private slots: void removeInEmptyHash(); void valueInEmptyHash(); void fineTuningInEmptyHash(); + + void reserveShared(); }; struct IdentityTracker { @@ -2598,5 +2600,20 @@ void tst_QHash::fineTuningInEmptyHash() QVERIFY(hash.capacity() > 0); } +void tst_QHash::reserveShared() +{ + QHash<char, char> hash; + hash.insert('c', 'c'); + auto hash2 = hash; + + QCOMPARE(hash2.capacity(), hash.capacity()); + auto oldCap = hash.capacity(); + + hash2.reserve(100); // This shouldn't crash + + QVERIFY(hash2.capacity() >= 100); + QCOMPARE(hash.capacity(), oldCap); +} + QTEST_APPLESS_MAIN(tst_QHash) #include "tst_qhash.moc" |