Skip to content

Commit

Permalink
Fix UB in tst_QSharedPointer::basics()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Lars Knoll <[email protected]>
Reviewed-by: Olivier Goffart (Woboq GmbH) <[email protected]>
  • Loading branch information
marc-kdab committed Jan 7, 2016
1 parent 9c7be0a commit c38b14e
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit c38b14e

Please sign in to comment.