QSocks5SocketEngine: don't depend on zero-initialization of QBasicAtomic

It's unclear¹ whether static zero-initialization of a static
QBasicAtomic actually initializes the object with a zero value, or
whether it remains default-constructed (without a value until a
following call to std::atomic_init gives it one).

Play it safe and use Q_BASIC_ATOMIC_INITIALIZER(0) to dodge any issues
the old code may have had.

¹ see ongoing discussion on the Jira ticket

Amends 04d6495bf773a6bb0d4fa6980df22d3b81a605b0.

Task-number: QTBUG-137465
Pick-to: 6.8 6.5
Change-Id: Iee0d75ce10a589390afdd9069b7040a1c9c608e1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit e4b0549a4c3f55828488fad6e6f5723072d6a291)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 6b77b43b1a231dc0aafad15fb3220e86c6787eea)
This commit is contained in:
Marc Mutz 2025-06-06 20:19:53 +02:00 committed by Qt Cherry-pick Bot
parent b9a9f4deee
commit ae5dd04b5a

View File

@ -966,7 +966,7 @@ QSocks5SocketEngine::~QSocks5SocketEngine()
static int nextDescriptor() static int nextDescriptor()
{ {
static QBasicAtomicInt counter; Q_CONSTINIT static QBasicAtomicInt counter = Q_BASIC_ATOMIC_INITIALIZER(0);
return 1 + counter.fetchAndAddRelaxed(1); return 1 + counter.fetchAndAddRelaxed(1);
} }