From 17d231039b53c03e67d025f1f72bbd529e98fcbd Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 13 Dec 2017 21:29:21 +0000 Subject: Don't crash with null receiver/context in new-style connects old style connects have protection against null sender and null receiver, but new style only had against null sender. Change-Id: Ie555ac078412918e60c3b60830fe1f3abfb7f5af Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 642d48d721..f1e58921c0 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -150,6 +150,7 @@ private slots: void deleteLaterInAboutToBlockHandler(); void mutableFunctor(); void checkArgumentsForNarrowing(); + void nullReceiver(); }; struct QObjectCreatedOnShutdown @@ -7380,6 +7381,16 @@ void tst_QObject::checkArgumentsForNarrowing() #undef FITS } +void tst_QObject::nullReceiver() +{ + QObject o; + QObject *nullObj = nullptr; // Passing nullptr directly doesn't compile with gcc 4.8 + QVERIFY(!connect(&o, &QObject::destroyed, nullObj, &QObject::deleteLater)); + QVERIFY(!connect(&o, &QObject::destroyed, nullObj, [] {})); + QVERIFY(!connect(&o, &QObject::destroyed, nullObj, Functor_noexcept())); + QVERIFY(!connect(&o, SIGNAL(destroyed()), nullObj, SLOT(deleteLater()))); +} + // Test for QtPrivate::HasQ_OBJECT_Macro Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro::Value); Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro::Value); -- cgit v1.2.3