From 90d96766aff31e65fd5d0f9dbbd2f527f45f0cec Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 3 Jul 2023 08:05:03 +0200 Subject: [PATCH] QEventLoopLocker: defend against nullptr arguments The class would previosuly produce a crash when the QEventLoop* or the QThread* were nullptr or if no QCoreApplication existed. We want, however, the out-of-line constructors of the class to be noexcept, and for that, they should neither allocation nor have preconditions. The former is for another patch; this patch deals with the latter. [ChangeLog][QtCore][QEventLoopLocker] Is now a no-op on nullptr QEventLoop*, QThread*, QCoreApplication::instance() (was: crash). Task-number: QTBUG-114793 Change-Id: I4246f74008df6ad7fcbfde56403397b065fbe861 Reviewed-by: Thiago Macieira Reviewed-by: Fabian Kosmale (cherry picked from commit 3748b194d4de790540aa74db8d65b602e097f415) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qeventloop.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index edde9492f88..f348708aad0 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -407,6 +407,8 @@ void QEventLoopLocker::visit(Func f) const { using Type = QEventLoopLockerPrivate::Type; const auto ptr = d_ptr->pointer(); + if (!ptr) + return; switch (d_ptr->type()) { case Type::EventLoop: return f(static_cast(ptr)); case Type::Thread: return f(static_cast(ptr));