diff options
author | Marc Mutz <[email protected]> | 2025-06-06 16:40:48 +0200 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2025-06-09 15:18:23 +0200 |
commit | 231069963d9fa91736a377de4d3e77307374412f (patch) | |
tree | f3ee08d0811d8f7102a54fbe674a6a1c72326f2e | |
parent | 0ba05ca500ecb1269b3ba67761e1329e0934f40c (diff) |
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 <[email protected]>
-rw-r--r-- | src/corelib/global/qlogging.cpp | 4 |
1 files 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){ |