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.9 6.8 6.5
Change-Id: I63bccb1bf3ff45d539af4efe6843d2c648d7cb86
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Ulf Hermann 2025-02-26 09:57:41 +01:00
parent 1145e1709d
commit 177cd123d2

View File

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