tst_QGlobal: work around ubsan issue in toString(qint128)

Found a problem on GCC 9.4 where asan/ubsan seems to break
std::numeric_limits<int128>::min():

    runtime error: negation of 0x80000000000000000000000000000000 cannot be represented in type '__int128'; cast to an unsigned type to negate this value to itself

This is the -i _after_ we've already checked for ::min() two lines
above. It works with Q_INT128_MIN, though, so use that.

Change-Id: I778980baf4e7eea9f8de06697d792241314acacd
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit 28f1eb6c838529675613f05f990255d3b0a22f3a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-09-14 18:22:12 +02:00 committed by Qt Cherry-pick Bot
parent 0025362dd1
commit ed53eb67fe

View File

@ -35,7 +35,7 @@ namespace detail {
template <>
char *toString(const qint128 &i)
{
if (i == std::numeric_limits<qint128>::min()) // -i is not representable, hardcode:
if (i == Q_INT128_MIN) // -i is not representable, hardcode:
return qstrdup("-170141183460469231731687303715884105728");
std::array<char, 64> buffer;
auto dst = detail::i128ToStringHelper(buffer, i < 0 ? -i : i);