summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-01-06 23:17:03 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-01-07 13:00:40 +0000
commitc38b14e2519a2bdbd835e52ee699ae9ac3f45d00 (patch)
treea539e7bf79d7d982c1655c555e651316c52cdcce /tests
parent9c7be0a7ec92a28d5d489fb78c500dad3f01d9ec (diff)
Fix UB in tst_QSharedPointer::basics()
Binding a reference to the nullptr is undefined behavior. Just skip that particular test when 'ptr' is null. Found by UBSan: tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp:258:32: runtime error: reference binding to null pointer of type 'struct Data' Change-Id: I125588b9d269a6f76716d660d03142f409513885 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 7741803224..7538eaf378 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -246,8 +246,10 @@ void tst_QSharedPointer::basics()
QCOMPARE(ptr.data(), aData);
QCOMPARE(ptr.operator->(), aData);
- Data &dataReference = *ptr;
- QCOMPARE(&dataReference, aData);
+ if (!isNull) {
+ Data &dataReference = *ptr;
+ QCOMPARE(&dataReference, aData);
+ }
QVERIFY(ptr == aData);
QVERIFY(!(ptr != aData));