From 992a37234c5ec7494fc2f24217d36400f6c1630a Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 3 Oct 2011 15:21:02 +0200 Subject: Don't crash by modifying read-only shared_null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Functions that modify the d-pointer must detach or otherwise take measures to not modify the const, read-only shared_null. The setSharable(bool) function takes care to detach when setting sharable to false, but should avoid setting the sharable data member unless d is not the shared null. Similarly, QMap::setInsertInOrder() needs to detach if it is shared with the shared_null (the logic has been updated to be the same as setSharable()). Change-Id: Ida5cb9818b86695f1b9f0264418b955c56424898 Reviewed-on: http://codereview.qt-project.org/5929 Reviewed-by: Qt Sanity Bot Reviewed-by: Bradley T. Hughes Reviewed-by: Jan-Arve Sæther --- tests/auto/corelib/tools/qlist/tst_qlist.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto/corelib/tools/qlist') diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index 3901b6ffe8..3d062919da 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -91,6 +91,8 @@ private slots: void testOperators() const; void initializeList() const; + + void const_shared_null() const; }; void tst_QList::length() const @@ -688,5 +690,16 @@ void tst_QList::initializeList() const #endif } +void tst_QList::const_shared_null() const +{ + QList list1; + list1.setSharable(false); + QVERIFY(list1.isDetached()); + + QList list2; + list2.setSharable(true); + QVERIFY(!list2.isDetached()); +} + QTEST_APPLESS_MAIN(tst_QList) #include "tst_qlist.moc" -- cgit v1.2.3