diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-01-24 08:29:51 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-01-30 09:29:12 +0100 |
commit | d5669a48549eaf53163a5ce629326ea763d01941 (patch) | |
tree | b89dad96a93259b4c75f24bd146d73e8990f5212 | |
parent | dca3d467a7545f3012d05aa027f2865f6b857a3f (diff) |
Fix tests in QHash that would read beyond end()
A couple of tests in the QHash autotest could iterate beyond
end(), leading to undefined behavior. This is bound to crash
with the new upcoming QHash implementation.
Change-Id: I977fc939e6e472f05b7cb2fa0a79c2d5f8782f45
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | tests/auto/corelib/tools/qhash/tst_qhash.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 5dc1800569..4052eff0ae 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -1080,7 +1080,15 @@ void tst_QHash::keyIterator() QVERIFY(key_it != hash.keyEnd()); QCOMPARE(*key_it, it.key()); QCOMPARE(*(key_it++), (it++).key()); - QCOMPARE(*(++key_it), (++it).key()); + if (key_it != hash.keyEnd()) { + QVERIFY(it != hash.end()); + ++key_it; + ++it; + if (key_it != hash.keyEnd()) + QCOMPARE(*key_it, it.key()); + else + QVERIFY(it == hash.end()); + } QCOMPARE(std::count(hash.keyBegin(), hash.keyEnd(), 99), 1); @@ -1125,7 +1133,10 @@ void tst_QHash::keyValueIterator() ++it; ++key_value_it; - QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); + if (it != hash.end()) + QCOMPARE(*key_value_it, entry_type(it.key(), it.value())); + else + QVERIFY(key_value_it == hash.constKeyValueEnd()); key = 99; value = 99 * 100; |