From 1022922037e794f3687d7c58f8b2caa44343a43b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 16 Aug 2022 07:32:42 -0700 Subject: [PATCH] QSemaphore: Fix warnings about shift exceeding size on 32-bit error: right shift count >= width of type [-Werror=shift-count-overflow] Pick-to: 6.4 Fixes: QTBUG-105687 Change-Id: Ic6547f8247454b47baa8fffd170bd9cd0e2a8ca3 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/thread/qsemaphore.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 664085eb2b9..803aa30bef3 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -161,7 +161,7 @@ futexSemaphoreTryAcquire_loop(QBasicAtomicInteger &u, quintptr curValu if constexpr (futexHasWaiterCount) { Q_ASSERT(n > 1); ptr = futexHigh32(&u); - curValue >>= 32; + curValue = quint64(curValue) >> 32; } } @@ -213,7 +213,8 @@ template bool futexSemaphoreTryAcquire(QBasicAtomicInteger> 32) & 0x7fffffffU) == 0x7fffffffU) { + quint32 waiterCount = (quint64(curValue) >> 32) & 0x7fffffffU; + if (waiterCount == 0x7fffffffU) { qCritical() << "Waiter count overflow in QSemaphore"; return false; }