From 2f8a08f31b1bfdc18766bae4983d238ee1cf716c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Jun 2017 15:06:09 -0700 Subject: Make qt_check_pointer more OOM-safe First, it can never return, so we can mark it Q_NORETURN and add an std::termianate at the end. Though if it did, we'd end up in a null- pointer dereference crash in the caller. Second, add Q_DECL_NOTHROW to it. It can't throw, but it terminates execution. This also prevents both puts and fprintf from escaping via pthread asynchronous cancellation on Linux/glibc. Third, don't use QMessageLogger, since that allocates memory and actually uses QString. If we really are in an OOM situation, then QString's failed allocation would recurse back into qt_check_pointer. We'd compound the OOM situation with a stack overflow... Change-Id: Ia53158e207a94bf49489fffd14c81c47971f4e82 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/global/qglobal.h') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index f2f28343c6..0c74ed4a3e 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -753,7 +753,7 @@ template <> class QStaticAssertFailure {}; #define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition) #endif -Q_CORE_EXPORT void qt_check_pointer(const char *, int); +Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) Q_DECL_NOTHROW; Q_CORE_EXPORT void qBadAlloc(); #ifdef QT_NO_EXCEPTIONS -- cgit v1.2.3