diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-07-03 08:05:03 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-07-04 18:29:36 +0000 |
commit | 3748b194d4de790540aa74db8d65b602e097f415 (patch) | |
tree | 5516f7b4dfdc2516cfce62014c3267f1957f5373 /src/corelib/kernel/qeventloop.cpp | |
parent | d18a9dd977a59bf735ed3b6a19e101d4b26a1cef (diff) |
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
Pick-to: 6.6
Change-Id: I4246f74008df6ad7fcbfde56403397b065fbe861
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qeventloop.cpp')
-rw-r--r-- | src/corelib/kernel/qeventloop.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 768175257f..edd09581ef 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -423,6 +423,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<QEventLoopPrivate *>(ptr)); case Type::Thread: return f(static_cast<QThreadPrivate *>(ptr)); |