From 746ab5f16d5c297567341797869b124868a926fe Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 2 Oct 2019 15:12:17 +0200 Subject: Remove potential out of bounds accesses to QList Change-Id: I13431e45ef329921a8846c38047f704a299a1a94 Reviewed-by: Marc Mutz Reviewed-by: Frederik Gladhorn --- src/corelib/kernel/qobject.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/corelib/kernel/qobject.cpp') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index cf107498dd..fb0d54c801 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2157,7 +2157,9 @@ void QObjectPrivate::setParent_helper(QObject *o) // cleared our entry in parentD->children. } else { const int index = parentD->children.indexOf(q); - if (parentD->isDeletingChildren) { + if (index < 0) { + // we're probably recursing into setParent() from a ChildRemoved event, don't do anything + } else if (parentD->isDeletingChildren) { parentD->children[index] = 0; } else { parentD->children.removeAt(index); -- cgit v1.2.3 From f67481094fa7f16dec281f9a96dd0de3dc0c453f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 9 Oct 2019 23:35:06 +0200 Subject: QObject: use delegate constructors Avoid the massive code duplication in the two QObject constructors. The only slight difference is the code path checking for isWidget; I'd say that paying for that one is worth the price of de-duplicating. Change-Id: I3af749738fe7d6b7adf287009d1815396a2f1407 Reviewed-by: Lars Knoll --- src/corelib/kernel/qobject.cpp | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'src/corelib/kernel/qobject.cpp') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index fb0d54c801..bb1b48b0a6 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -906,30 +906,8 @@ static bool check_parent_thread(QObject *parent, */ QObject::QObject(QObject *parent) - : d_ptr(new QObjectPrivate) + : QObject(*new QObjectPrivate, parent) { - Q_ASSERT_X(this != parent, Q_FUNC_INFO, "Cannot parent a QObject to itself"); - - Q_D(QObject); - d_ptr->q_ptr = this; - d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current(); - d->threadData->ref(); - if (parent) { - QT_TRY { - if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData)) - parent = 0; - setParent(parent); - } QT_CATCH(...) { - d->threadData->deref(); - QT_RETHROW; - } - } -#if QT_VERSION < 0x60000 - qt_addObject(this); -#endif - if (Q_UNLIKELY(qtHookData[QHooks::AddQObject])) - reinterpret_cast(qtHookData[QHooks::AddQObject])(this); - Q_TRACE(QObject_ctor, this); } /*! -- cgit v1.2.3