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 <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
77347a3699
commit
17d231039b
@ -4796,7 +4796,7 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
|
||||
QtPrivate::QSlotObjectBase *slotObj, Qt::ConnectionType type,
|
||||
const int *types, const QMetaObject *senderMetaObject)
|
||||
{
|
||||
if (!sender || !slotObj || !senderMetaObject) {
|
||||
if (!sender || !receiver || !slotObj || !senderMetaObject) {
|
||||
qWarning("QObject::connect: invalid null parameter");
|
||||
if (slotObj)
|
||||
slotObj->destroyIfLastRef();
|
||||
|
@ -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<tst_QObject>::Value);
|
||||
Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user