qt6-bb10/tests/auto/corelib/text
Marc Mutz 73c44c8381 QLocale: fix UB (signed overflow) in formattedDataSize()
Coverity complains that qCountLeadingZeroBits() may return 64 and then
the RHS will be out-of-range for int. Of course, 64 leading zero bits
means that the argument is 0, which we excluded in the first `if` of
the if-else chain.

I can only guess (because it doesn't tell me which value of `bytes` it
is using for the analysis) that Coverity assumes bytes ==
numeric_limits<qint64>::min() and considers the overflow in qAbs() to
yield a 0, because, it being UB, it may yield anything.

Be that as it may, the fact remains that formattedDataSize() invokes
UB when passed numeric_limits<qint64>::min(), as confirmed by ubsan:

   global/qnumeric.h:479:26: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself
   text/qlocale.cpp:5062:82: runtime error: signed integer overflow: -2147483648 * 3 cannot be represented in type 'int'
   text/qlocale.cpp:5062:26: runtime error: division by zero
   FAIL!  : tst_QLocale::formattedDataSize(English-Decimal-min) Compared values are not the same
      Actual   (QLocale(language).formattedDataSize(bytes, decimalPlaces, units)): "-inf bytes"
      Expected ("output")                                                        : "-9.22 EB"

So fix the overflow by using the new QtPrivate::qUnsignedAbs(). Then
sit back and await Coverity's verdict on the next run.

[ChangeLog][QtCore][QLocale] Fix issue when calling
formattedDataSize() with numeric_limits<qint64>::min().

Amends 9d23aebb27.

Pick-to: 6.5 6.2 5.15
Coverity-Id: 474294
Change-Id: I9a5a5acbdcf881a624bb827ca1dd970771f1bb6e
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit b93575de01760ff2ab0d817557a642c71cdb4414)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 6cefb8be965759cc022ce3ef1ae7a722f0566ce7)
2025-02-21 21:24:30 +00:00
..
qanystringview tst_QAnyStringView: test which chars magically convert 2025-02-11 00:49:25 +00:00
qbytearray QByteArray(View)::lastIndexOf: Guard against needle > haystack 2025-02-15 04:17:33 +00:00
qbytearray_large Add REUSE.toml files 2024-11-07 08:38:49 +01:00
qbytearrayapisymmetry Blacklist tests requiring parsing text > 255 chars on VxWorks 2024-06-26 22:52:30 +00:00
qbytearraylist Change license for tests files 2024-02-04 09:56:42 +01:00
qbytearraymatcher Change license for tests files 2024-02-04 09:56:42 +01:00
qbytearrayview tst_QByteArrayView: stop using std::basic_string<signed char> 2025-02-15 04:17:33 +00:00
qbytedatabuffer Change license for tests files 2024-02-04 09:56:42 +01:00
qchar Add REUSE.toml files 2024-11-07 08:38:49 +01:00
qcollator Change license for tests files 2024-02-04 09:56:42 +01:00
qlatin1stringmatcher QStaticLatin1StringMatcher: add indexIn(QStringView) 2024-05-08 22:05:35 +02:00
qlatin1stringview Confirm QLatin1StringView can be constructed over arrays of unknown bounds 2024-12-11 06:29:18 +00:00
qlocale QLocale: fix UB (signed overflow) in formattedDataSize() 2025-02-21 21:24:30 +00:00
qregularexpression QRegularExpression: coalesce consecutive * tokens in wildcards 2024-08-08 01:09:59 +00:00
qstring tst_QString: extend arg() tests with enums w/o explicit underlying_type 2024-12-13 08:00:16 +00:00
qstring_no_cast_from_bytearray Change license for tests files 2024-02-04 09:56:42 +01:00
qstringapisymmetry tst_QStringApiSymmetry: test QByteArray(weak)/QByteArrayView overloading 2024-12-13 08:00:16 +00:00
qstringbuilder tst_QStringBuilder: add more checks 2024-06-12 12:23:43 +00:00
qstringconverter tst_QStringConverter: compare pointer distances, not pointers 2024-06-07 06:59:22 +00:00
qstringiterator Change license for tests files 2024-02-04 09:56:42 +01:00
qstringlist Change license for tests files 2024-02-04 09:56:42 +01:00
qstringmatcher Change license for tests files 2024-02-04 09:56:42 +01:00
qstringtokenizer Change license for tests files 2024-02-04 09:56:42 +01:00
qstringview Q{Any,Utf8}StringView: fix construction from arrays of unknown size 2024-12-16 20:45:24 +00:00
qtextboundaryfinder Update UCD to Unicode 16.0.0 2025-02-17 14:39:31 +01:00
qunicodetools Change license for tests files 2024-02-04 09:56:42 +01:00
shared Change license for tests files 2024-02-04 09:56:42 +01:00
CMakeLists.txt tst_QStringApiSymmetry: disable for WASM 2024-08-25 10:21:14 +00:00