diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-02-21 09:57:09 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-02-22 13:45:50 +0000 |
commit | 6716fe8cfdeb5f8cd63d6dde8252b25d86622404 (patch) | |
tree | 7b2aec6aaad0335b509718e32d2fb54a2a8e3390 /tests/auto/corelib/tools/qvector/tst_qvector.cpp | |
parent | 9a950655feb709ea515edbbdb66fa5d900dc62ec (diff) |
QVector: fix use of invalid iterators in removeAll()
The c2m() function which converts a const_iterator into an iterator
is a broken concept for an implicitly shared container such as
QVector, because the act of calling begin() as the starting
point already detaches and invalidates the c2m argument.
This could be fixed in c2m, but the bug wasn't even in c2m,
but in removeAll(), which called end() before c2m, so the c2m
argument was already invalidated when entering c2m.
The solution is to store the positions as indices instead of
iterators before calling the first detaching function.
Task-number: QTBUG-44592
Change-Id: I66cf4f1277e71148a4d5b5bbfb6a3369ad02db68
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/tools/qvector/tst_qvector.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qvector/tst_qvector.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 9a79d48472..256fa5e507 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -1500,11 +1500,18 @@ void tst_QVector::remove() const QVERIFY(myvec.removeOne(val2)); QCOMPARE(myvec, QVector<T>() << val1 << val3 << val1 << val3 << val1 << val2 << val3); + QVector<T> myvecCopy = myvec; + QVERIFY(myvecCopy.isSharedWith(myvec)); // removeAll() QCOMPARE(myvec.removeAll(val4), 0); + QVERIFY(myvecCopy.isSharedWith(myvec)); QCOMPARE(myvec.removeAll(val1), 3); + QVERIFY(!myvecCopy.isSharedWith(myvec)); QCOMPARE(myvec, QVector<T>() << val3 << val3 << val2 << val3); + myvecCopy = myvec; + QVERIFY(myvecCopy.isSharedWith(myvec)); QCOMPARE(myvec.removeAll(val2), 1); + QVERIFY(!myvecCopy.isSharedWith(myvec)); QCOMPARE(myvec, QVector<T>() << val3 << val3 << val3); // remove rest |