QByteArray: Make gcc 12 happy

It somehow concludes that asize may be negative and would then cast to
an obscenely large size_t. This produces the following warning:

.../qbytearray.cpp: In member function ‘replace.constprop.isra’:
.../qbytearray.cpp:2579:23: warning: ‘memcpy’ specified bound between 9223372036854775808 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
 2579 |                 memcpy(d + to, a, asize);
      |                       ^

Check for asize > 0 rather than asize != 0.

Pick-to: 6.8 6.5
Change-Id: I63bccb1bf3ff45d539af4efe6843d2c648d7cb86
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 177cd123d29f818413db4bb7a9d92b8485c95947)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ulf Hermann 2025-02-26 09:57:41 +01:00 committed by Qt Cherry-pick Bot
parent 8159f4626b
commit b9169c1210

View File

@ -2551,7 +2551,7 @@ QByteArray &QByteArray::replace(QByteArrayView before, QByteArrayView after)
} else {
to = index;
}
if (asize) {
if (asize > 0) {
memcpy(d + to, a, asize);
to += asize;
}