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>bb10
parent
dca3d467a7
commit
d5669a4854
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue