From 231069963d9fa91736a377de4d3e77307374412f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 6 Jun 2025 16:40:48 +0200 Subject: [PATCH] QLogging: fix potential UB in QBasicAtomic initialization Until C++17 (inclusive), a default-constructed std::atomic object can, officially, only be initialized with a call to std::atomic_init, for which QBasicAtomic doesn't have API. It is even unclear whether zero-initialization of static and thread-local objects will cause the object to be initialized. But initialization with = {} is definitely fishy, because that, by definition, invokes the problematic default constructor. So make the initialization explict with Q_BASIC_ATOMIC_INITIALIZER(0) instead. Amends 4a154170773199f5b3376496c7b1a1c4530744e9. Task-number: QTBUG-137465 Pick-to: 6.10 Change-Id: I177e05c09e20e0830af7bf1ccb650afc860ab9d5 Reviewed-by: Thiago Macieira --- src/corelib/global/qlogging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 3637bd72c91..8373f63b86c 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -181,8 +181,8 @@ static bool isFatalCountDown(const char *varname, QBasicAtomicInt &n) return v == ImmediatelyFatal; } -Q_CONSTINIT static QBasicAtomicInt fatalCriticalsCount = {}; -Q_CONSTINIT static QBasicAtomicInt fatalWarningsCount = {}; +Q_CONSTINIT static QBasicAtomicInt fatalCriticalsCount = Q_BASIC_ATOMIC_INITIALIZER(0); +Q_CONSTINIT static QBasicAtomicInt fatalWarningsCount = Q_BASIC_ATOMIC_INITIALIZER(0); static bool isFatal(QtMsgType msgType) { switch (msgType){