Replace {add,sub,mul}_overload with q{Add,Sub,Mul}Overload

These APIs started out as private APIs in qnumeric_p.h, but have since
been made pseudo-public in qnumeric.h. The qnumeric_p.h versions just
forward to the qnumeric.h ones, so just use the latter.

This is in preparation of removing the {add,sub,mul}_overflow
versions, which, despite being defined in the unnamed namespace, don't
sport the q prefix, so potentially clash with global symbols.

The change is a simple textual search and replace, manually excluding
qnumeric_p.h.

Picking to 6.5 to avoid cherry-pick conflicts going forward.

Change-Id: Ic0f7c92f7c47923317109e8a9dc06fa66bdff2c2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b209f943d2611fa4ac2dd9c64b1a014182b59a3d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-03-20 12:33:02 +01:00 committed by Qt Cherry-pick Bot
parent 9b6d4f542f
commit e75305dd42
13 changed files with 82 additions and 82 deletions

View File

@ -1564,7 +1564,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory
qint64 max = resource.uncompressedSize();
qint64 end;
if (offset < 0 || size <= 0 || !resource.isValid() ||
add_overflow(offset, size, &end) || end > max) {
qAddOverflow(offset, size, &end) || end > max) {
q->setError(QFile::UnspecifiedError, QString());
return nullptr;
}

View File

@ -132,7 +132,7 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, QString *output)
// delta = delta + (m - n) * (h + 1), fail on overflow
uint tmp;
if (mul_overflow<uint>(m - n, h + 1, &tmp) || add_overflow<uint>(delta, tmp, &delta)) {
if (qMulOverflow<uint>(m - n, h + 1, &tmp) || qAddOverflow<uint>(delta, tmp, &delta)) {
output->truncate(outLen);
return; // punycode_overflow
}
@ -144,7 +144,7 @@ Q_AUTOTEST_EXPORT void qt_punycodeEncoder(QStringView in, QString *output)
// increase delta until we reach the character processed in this iteration;
// fail if delta overflows.
if (c < n) {
if (add_overflow<uint>(delta, 1, &delta)) {
if (qAddOverflow<uint>(delta, 1, &delta)) {
output->truncate(outLen);
return; // punycode_overflow
}
@ -219,7 +219,7 @@ Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc)
// i = i + digit * w, fail on overflow
uint tmp;
if (mul_overflow<uint>(digit, w, &tmp) || add_overflow<uint>(i, tmp, &i))
if (qMulOverflow<uint>(digit, w, &tmp) || qAddOverflow<uint>(i, tmp, &i))
return QString();
// detect threshold to stop reading delta digits
@ -231,7 +231,7 @@ Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc)
if (digit < t) break;
// w = w * (base - t), fail on overflow
if (mul_overflow<uint>(w, base - t, &w))
if (qMulOverflow<uint>(w, base - t, &w))
return QString();
}
@ -241,7 +241,7 @@ Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc)
bias = adapt(i - oldi, outputLength + 1, oldi == 0);
// n = n + i div (length(output) + 1), fail on overflow
if (add_overflow<uint>(n, i / (outputLength + 1), &n))
if (qAddOverflow<uint>(n, i / (outputLength + 1), &n))
return QString();
// allow the deltas to wrap around

View File

@ -682,7 +682,7 @@ static CborError qt_cbor_decoder_transfer_string(void *token, const void **userp
// (otherwise, we'd lose the length information)
qsizetype total;
if (len > size_t(std::numeric_limits<QByteArray::size_type>::max())
|| add_overflow<qsizetype>(offset, len, &total))
|| qAddOverflow<qsizetype>(offset, len, &total))
return CborErrorDataTooLarge;
// our string transfer is just saving the offset to the userptr
@ -1544,7 +1544,7 @@ QCborStreamReaderPrivate::readStringChunk_byte(ReadStringChunk params, qsizetype
// See note above on having ensured there is enough incoming data.
auto oldSize = params.array->size();
auto newSize = oldSize;
if (add_overflow<decltype(newSize)>(oldSize, toRead, &newSize)) {
if (qAddOverflow<decltype(newSize)>(oldSize, toRead, &newSize)) {
handleError(CborErrorDataTooLarge);
return -1;
}

View File

@ -787,9 +787,9 @@ static QCborValue::Type convertToExtendedType(QCborContainerPrivate *d)
bool ok = false;
if (e.type == QCborValue::Integer) {
#if QT_POINTER_SIZE == 8
// we don't have a fast 64-bit mul_overflow implementation on
// we don't have a fast 64-bit qMulOverflow implementation on
// 32-bit architectures.
ok = !mul_overflow(e.value, qint64(1000), &msecs);
ok = !qMulOverflow(e.value, qint64(1000), &msecs);
#else
static const qint64 Limit = std::numeric_limits<qint64>::max() / 1000;
ok = (e.value > -Limit && e.value < Limit);

View File

@ -2583,8 +2583,8 @@ static QTime msecsToTime(qint64 msecs)
// The inputs should not have opposite signs.
static inline bool daysAndMillisOverflow(qint64 days, qint64 millisInDay, qint64 *sumMillis)
{
return mul_overflow(days, std::integral_constant<qint64, MSECS_PER_DAY>(), sumMillis)
|| add_overflow(*sumMillis, millisInDay, sumMillis);
return qMulOverflow(days, std::integral_constant<qint64, MSECS_PER_DAY>(), sumMillis)
|| qAddOverflow(*sumMillis, millisInDay, sumMillis);
}
// Converts a date/time value into msecs
@ -2680,7 +2680,7 @@ QDateTimePrivate::ZoneState QDateTimePrivate::expressUtcAsLocal(qint64 utcMSecs)
#if QT_CONFIG(timezone) // Use the system time-zone.
if (const auto sys = QTimeZone::systemTimeZone(); sys.isValid()) {
result.offset = sys.d->offsetFromUtc(utcMSecs);
if (add_overflow(utcMSecs, result.offset * MSECS_PER_SEC, &result.when))
if (qAddOverflow(utcMSecs, result.offset * MSECS_PER_SEC, &result.when))
return result;
result.dst = sys.d->isDaylightTime(utcMSecs) ? DaylightTime : StandardTime;
result.valid = true;
@ -2697,15 +2697,15 @@ QDateTimePrivate::ZoneState QDateTimePrivate::expressUtcAsLocal(qint64 utcMSecs)
const auto fakeJd = QGregorianCalendar::julianFromParts(systemTimeYearMatching(ymd.year),
ymd.month, ymd.day);
if (Q_UNLIKELY(!fakeJd
|| mul_overflow(jd - *fakeJd, std::integral_constant<qint64, MSECS_PER_DAY>(),
|| qMulOverflow(jd - *fakeJd, std::integral_constant<qint64, MSECS_PER_DAY>(),
&diffMillis)
|| sub_overflow(utcMSecs, diffMillis, &fakeUtc))) {
|| qSubOverflow(utcMSecs, diffMillis, &fakeUtc))) {
return result;
}
result = QLocalTime::utcToLocal(fakeUtc);
// Now correct result.when for the use of the fake date:
if (!result.valid || add_overflow(result.when, diffMillis, &result.when)) {
if (!result.valid || qAddOverflow(result.when, diffMillis, &result.when)) {
// If utcToLocal() failed, its return has the fake when; restore utcMSecs.
// Fail on overflow, but preserve offset and DST-ness.
result.when = utcMSecs;
@ -2784,7 +2784,7 @@ QDateTimePrivate::ZoneState QDateTimePrivate::localStateAtMillis(qint64 millis,
auto result = QLocalTime::mapLocalTime(fake.shifted, dst);
if (result.valid) {
qint64 adjusted;
if (Q_UNLIKELY(add_overflow(result.when, millis - fake.shifted, &adjusted))) {
if (Q_UNLIKELY(qAddOverflow(result.when, millis - fake.shifted, &adjusted))) {
using Bound = std::numeric_limits<qint64>;
adjusted = millis < fake.shifted ? Bound::min() : Bound::max();
}
@ -4008,7 +4008,7 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs)
if (QTimeZone::isUtcOrFixedOffset(spec)) {
if (spec == Qt::OffsetFromUTC)
state.offset = d->m_offsetFromUtc;
if (!state.offset || !add_overflow(msecs, state.offset * MSECS_PER_SEC, &state.when))
if (!state.offset || !qAddOverflow(msecs, state.offset * MSECS_PER_SEC, &state.when))
status |= QDateTimePrivate::ValidityMask;
} else if (spec == Qt::LocalTime) {
state = QDateTimePrivate::expressUtcAsLocal(msecs);
@ -4021,7 +4021,7 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs)
state.offset = data.offsetFromUtc;
Q_ASSERT(state.offset >= -SECS_PER_DAY && state.offset <= SECS_PER_DAY);
if (!state.offset
|| !Q_UNLIKELY(add_overflow(msecs, state.offset * MSECS_PER_SEC, &state.when))) {
|| !Q_UNLIKELY(qAddOverflow(msecs, state.offset * MSECS_PER_SEC, &state.when))) {
d->m_status = mergeDaylightStatus(status | QDateTimePrivate::ValidityMask,
data.daylightTimeOffset
? QDateTimePrivate::DaylightTime
@ -4062,7 +4062,7 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs)
void QDateTime::setSecsSinceEpoch(qint64 secs)
{
qint64 msecs;
if (!mul_overflow(secs, std::integral_constant<qint64, MSECS_PER_SEC>(), &msecs)) {
if (!qMulOverflow(secs, std::integral_constant<qint64, MSECS_PER_SEC>(), &msecs)) {
setMSecsSinceEpoch(msecs);
} else if (d.isShort()) {
d.data.status &= ~int(QDateTimePrivate::ValidityMask);
@ -4344,7 +4344,7 @@ QDateTime QDateTime::addYears(int nyears) const
QDateTime QDateTime::addSecs(qint64 s) const
{
qint64 msecs;
if (mul_overflow(s, std::integral_constant<qint64, MSECS_PER_SEC>(), &msecs))
if (qMulOverflow(s, std::integral_constant<qint64, MSECS_PER_SEC>(), &msecs))
return QDateTime();
return addMSecs(msecs);
}
@ -4368,7 +4368,7 @@ QDateTime QDateTime::addMSecs(qint64 msecs) const
case Qt::LocalTime:
case Qt::TimeZone:
// Convert to real UTC first in case this crosses a DST transition:
if (!add_overflow(toMSecsSinceEpoch(), msecs, &msecs)) {
if (!qAddOverflow(toMSecsSinceEpoch(), msecs, &msecs)) {
dt.setMSecsSinceEpoch(msecs);
} else if (dt.d.isShort()) {
dt.d.data.status &= ~int(QDateTimePrivate::ValidityMask);
@ -4380,7 +4380,7 @@ QDateTime QDateTime::addMSecs(qint64 msecs) const
case Qt::UTC:
case Qt::OffsetFromUTC:
// No need to convert, just add on
if (add_overflow(getMSecs(d), msecs, &msecs)) {
if (qAddOverflow(getMSecs(d), msecs, &msecs)) {
if (dt.d.isShort()) {
dt.d.data.status &= ~int(QDateTimePrivate::ValidityMask);
} else {

View File

@ -176,15 +176,15 @@ inline std::optional<qint64> tmToJd(const struct tm &date)
// True if combining day and seconds overflows qint64; otherwise, sets *epochSeconds
inline bool daysAndSecondsOverflow(qint64 julianDay, qint64 daySeconds, qint64 *epochSeconds)
{
return mul_overflow(julianDay - JULIAN_DAY_FOR_EPOCH, IC(SECS_PER_DAY), epochSeconds)
|| add_overflow(*epochSeconds, daySeconds, epochSeconds);
return qMulOverflow(julianDay - JULIAN_DAY_FOR_EPOCH, IC(SECS_PER_DAY), epochSeconds)
|| qAddOverflow(*epochSeconds, daySeconds, epochSeconds);
}
// True if combining seconds and millis overflows; otherwise sets *epochMillis
inline bool secondsAndMillisOverflow(qint64 epochSeconds, qint64 millis, qint64 *epochMillis)
{
return mul_overflow(epochSeconds, IC(MSECS_PER_SEC), epochMillis)
|| add_overflow(*epochMillis, millis, epochMillis);
return qMulOverflow(epochSeconds, IC(MSECS_PER_SEC), epochMillis)
|| qAddOverflow(*epochMillis, millis, epochMillis);
}
#undef IC

View File

@ -196,11 +196,11 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
// minMSecs(), because at least one backend (Windows) uses it for a
// start-of-time fake transition, that we want previousTransition() to find.
const qint64 recent =
sub_overflow(forLocalMSecs, seventeenHoursInMSecs, &millis) || millis <= minMSecs()
qSubOverflow(forLocalMSecs, seventeenHoursInMSecs, &millis) || millis <= minMSecs()
? minMSecs() + 1 : millis; // Necessarily <= forLocalMSecs + 2.
// (Given that minMSecs() is std::numeric_limits<qint64>::min() + 1.)
const qint64 imminent =
add_overflow(forLocalMSecs, seventeenHoursInMSecs, &millis)
qAddOverflow(forLocalMSecs, seventeenHoursInMSecs, &millis)
? maxMSecs() : millis; // Necessarily >= forLocalMSecs
// At most one of those was clipped to its boundary value:
Q_ASSERT(recent < imminent && seventeenHoursInMSecs < imminent - recent + 2);
@ -362,7 +362,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
if (early == late // > 99% of the time
|| late == invalidSeconds()) {
if (early == invalidSeconds()
|| sub_overflow(forLocalMSecs, early * qint64(1000), &utcEpochMSecs)) {
|| qSubOverflow(forLocalMSecs, early * qint64(1000), &utcEpochMSecs)) {
return invalidData(); // Outside representable range
}
} else {

View File

@ -275,8 +275,8 @@ inline bool timeToMSecs(QDate date, QTime time, qint64 *msecs)
++daySinceEpoch;
msInDay -= MSECS_PER_DAY;
}
return mul_overflow(daySinceEpoch, std::integral_constant<qint64, MSECS_PER_DAY>(), &dayms)
|| add_overflow(dayms, msInDay, msecs);
return qMulOverflow(daySinceEpoch, std::integral_constant<qint64, MSECS_PER_DAY>(), &dayms)
|| qAddOverflow(dayms, msInDay, msecs);
}
qint64 calculateTransitionForYear(const SYSTEMTIME &rule, int year, int bias)
@ -291,7 +291,7 @@ qint64 calculateTransitionForYear(const SYSTEMTIME &rule, int year, int bias)
// If bias pushes us outside the representable range, clip to range
// (overflow went past the end bias pushed us towards; and
// invalidMSecs() is a representable value less than minMSecs()):
return bias && add_overflow(msecs, qint64(bias) * 60000, &msecs)
return bias && qAddOverflow(msecs, qint64(bias) * 60000, &msecs)
? (bias < 0 ? QTimeZonePrivate::minMSecs() : QTimeZonePrivate::maxMSecs())
: qMax(QTimeZonePrivate::minMSecs(), msecs);
}

View File

@ -54,8 +54,8 @@ qsizetype qCalculateBlockSize(qsizetype elementCount, qsizetype elementSize, qsi
Q_ASSERT(elementSize);
size_t bytes;
if (Q_UNLIKELY(mul_overflow(size_t(elementSize), size_t(elementCount), &bytes)) ||
Q_UNLIKELY(add_overflow(bytes, size_t(headerSize), &bytes)))
if (Q_UNLIKELY(qMulOverflow(size_t(elementSize), size_t(elementCount), &bytes)) ||
Q_UNLIKELY(qAddOverflow(bytes, size_t(headerSize), &bytes)))
return -1;
if (Q_UNLIKELY(qsizetype(bytes) < 0))
return -1;
@ -118,7 +118,7 @@ static inline qsizetype reserveExtraBytes(qsizetype allocSize)
constexpr qsizetype extra = qMax(sizeof(QByteArray::value_type), sizeof(QString::value_type));
if (Q_UNLIKELY(allocSize < 0))
return -1;
if (Q_UNLIKELY(add_overflow(allocSize, extra, &allocSize)))
if (Q_UNLIKELY(qAddOverflow(allocSize, extra, &allocSize)))
return -1;
return allocSize;
}

View File

@ -819,7 +819,7 @@ QImageData *QImageData::create(uchar *data, int width, int height, qsizetype bp
// recalculate the total with this value
params.bytesPerLine = bpl;
if (mul_overflow<qsizetype>(bpl, height, &params.totalSize))
if (qMulOverflow<qsizetype>(bpl, height, &params.totalSize))
return nullptr;
}

View File

@ -92,18 +92,18 @@ QImageData::calculateImageParameters(qsizetype width, qsizetype height, qsizetyp
// calculate the size, taking care of overflows
qsizetype bytes_per_line;
if (mul_overflow(width, depth, &bytes_per_line))
if (qMulOverflow(width, depth, &bytes_per_line))
return invalid;
if (add_overflow(bytes_per_line, qsizetype(31), &bytes_per_line))
if (qAddOverflow(bytes_per_line, qsizetype(31), &bytes_per_line))
return invalid;
// bytes per scanline (must be multiple of 4)
bytes_per_line = (bytes_per_line >> 5) << 2; // can't overflow
qsizetype total_size;
if (mul_overflow(height, bytes_per_line, &total_size))
if (qMulOverflow(height, bytes_per_line, &total_size))
return invalid;
qsizetype dummy;
if (mul_overflow(height, qsizetype(sizeof(uchar *)), &dummy))
if (qMulOverflow(height, qsizetype(sizeof(uchar *)), &dummy))
return invalid; // why is this here?
#if 1 || QT_VERSION < QT_VERSION_CHECK(6,0,0) // ### can only fix this if QImage dimensions are not int anymore
// Disallow images where width * depth calculations might overflow

View File

@ -109,9 +109,9 @@ QTextureFileData QAstcHandler::read()
int zBlocks = (zSz + header->blockDimZ - 1) / header->blockDimZ;
int byteCount = 0;
bool oob = mul_overflow(xBlocks, yBlocks, &byteCount)
|| mul_overflow(byteCount, zBlocks, &byteCount)
|| mul_overflow(byteCount, 16, &byteCount);
bool oob = qMulOverflow(xBlocks, yBlocks, &byteCount)
|| qMulOverflow(byteCount, zBlocks, &byteCount)
|| qMulOverflow(byteCount, 16, &byteCount);
res.setDataOffset(sizeof(AstcHeader));

View File

@ -434,33 +434,33 @@ template <typename Int> static void addOverflow_template()
#define ADD_COMPARE_NONOVF(v1, v2, expected) \
do { \
QCOMPARE(add_overflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(qAddOverflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(r, Int(expected)); \
QCOMPARE(add_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
QCOMPARE(qAddOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
QCOMPARE(r, Int(expected)); \
QCOMPARE(add_overflow<v2>(Int(v1), &r), false); \
QCOMPARE(qAddOverflow<v2>(Int(v1), &r), false); \
QCOMPARE(r, Int(expected)); \
} while (false)
#define ADD_COMPARE_OVF(v1, v2) \
do { \
QCOMPARE(add_overflow(Int(v1), Int(v2), &r), true); \
QCOMPARE(add_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
QCOMPARE(add_overflow<v2>(Int(v1), &r), true); \
QCOMPARE(qAddOverflow(Int(v1), Int(v2), &r), true); \
QCOMPARE(qAddOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
QCOMPARE(qAddOverflow<v2>(Int(v1), &r), true); \
} while (false)
#define SUB_COMPARE_NONOVF(v1, v2, expected) \
do { \
QCOMPARE(sub_overflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(qSubOverflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(r, Int(expected)); \
QCOMPARE(sub_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
QCOMPARE(qSubOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), false); \
QCOMPARE(r, Int(expected)); \
QCOMPARE(sub_overflow<v2>(Int(v1), &r), false); \
QCOMPARE(qSubOverflow<v2>(Int(v1), &r), false); \
QCOMPARE(r, Int(expected)); \
} while (false)
#define SUB_COMPARE_OVF(v1, v2) \
do { \
QCOMPARE(sub_overflow(Int(v1), Int(v2), &r), true); \
QCOMPARE(sub_overflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
QCOMPARE(sub_overflow<v2>(Int(v1), &r), true); \
QCOMPARE(qSubOverflow(Int(v1), Int(v2), &r), true); \
QCOMPARE(qSubOverflow(Int(v1), (std::integral_constant<Int, Int(v2)>()), &r), true); \
QCOMPARE(qSubOverflow<v2>(Int(v1), &r), true); \
} while (false)
// basic values
@ -611,18 +611,18 @@ template <typename Int> static void mulOverflow_template()
#define MUL_COMPARE_NONOVF(v1, v2, expected) \
do { \
QCOMPARE(mul_overflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(qMulOverflow(Int(v1), Int(v2), &r), false); \
QCOMPARE(r, Int(expected)); \
QCOMPARE(mul_overflow(Int(v1), (std::integral_constant<Int, v2>()), &r), false); \
QCOMPARE(qMulOverflow(Int(v1), (std::integral_constant<Int, v2>()), &r), false); \
QCOMPARE(r, Int(expected)); \
QCOMPARE(mul_overflow<v2>(Int(v1), &r), false); \
QCOMPARE(qMulOverflow<v2>(Int(v1), &r), false); \
QCOMPARE(r, Int(expected)); \
} while (false);
#define MUL_COMPARE_OVF(v1, v2) \
do { \
QCOMPARE(mul_overflow(Int(v1), Int(v2), &r), true); \
QCOMPARE(mul_overflow(Int(v1), (std::integral_constant<Int, v2>()), &r), true); \
QCOMPARE(mul_overflow<v2>(Int(v1), &r), true); \
QCOMPARE(qMulOverflow(Int(v1), Int(v2), &r), true); \
QCOMPARE(qMulOverflow(Int(v1), (std::integral_constant<Int, v2>()), &r), true); \
QCOMPARE(qMulOverflow<v2>(Int(v1), &r), true); \
} while (false);
// basic multiplications
@ -723,28 +723,28 @@ void tst_QNumeric::signedOverflow()
const int maxInt = std::numeric_limits<int>::max();
int r;
QCOMPARE(add_overflow(minInt + 1, int(-1), &r), false);
QCOMPARE(add_overflow(minInt, int(-1), &r), true);
QCOMPARE(add_overflow(minInt, minInt, &r), true);
QCOMPARE(add_overflow(maxInt - 1, int(1), &r), false);
QCOMPARE(add_overflow(maxInt, int(1), &r), true);
QCOMPARE(add_overflow(maxInt, maxInt, &r), true);
QCOMPARE(qAddOverflow(minInt + 1, int(-1), &r), false);
QCOMPARE(qAddOverflow(minInt, int(-1), &r), true);
QCOMPARE(qAddOverflow(minInt, minInt, &r), true);
QCOMPARE(qAddOverflow(maxInt - 1, int(1), &r), false);
QCOMPARE(qAddOverflow(maxInt, int(1), &r), true);
QCOMPARE(qAddOverflow(maxInt, maxInt, &r), true);
QCOMPARE(sub_overflow(minInt + 1, int(1), &r), false);
QCOMPARE(sub_overflow(minInt, int(1), &r), true);
QCOMPARE(sub_overflow(minInt, maxInt, &r), true);
QCOMPARE(sub_overflow(maxInt - 1, int(-1), &r), false);
QCOMPARE(sub_overflow(maxInt, int(-1), &r), true);
QCOMPARE(sub_overflow(maxInt, minInt, &r), true);
QCOMPARE(qSubOverflow(minInt + 1, int(1), &r), false);
QCOMPARE(qSubOverflow(minInt, int(1), &r), true);
QCOMPARE(qSubOverflow(minInt, maxInt, &r), true);
QCOMPARE(qSubOverflow(maxInt - 1, int(-1), &r), false);
QCOMPARE(qSubOverflow(maxInt, int(-1), &r), true);
QCOMPARE(qSubOverflow(maxInt, minInt, &r), true);
QCOMPARE(mul_overflow(minInt, int(1), &r), false);
QCOMPARE(mul_overflow(minInt, int(-1), &r), true);
QCOMPARE(mul_overflow(minInt, int(2), &r), true);
QCOMPARE(mul_overflow(minInt, minInt, &r), true);
QCOMPARE(mul_overflow(maxInt, int(1), &r), false);
QCOMPARE(mul_overflow(maxInt, int(-1), &r), false);
QCOMPARE(mul_overflow(maxInt, int(2), &r), true);
QCOMPARE(mul_overflow(maxInt, maxInt, &r), true);
QCOMPARE(qMulOverflow(minInt, int(1), &r), false);
QCOMPARE(qMulOverflow(minInt, int(-1), &r), true);
QCOMPARE(qMulOverflow(minInt, int(2), &r), true);
QCOMPARE(qMulOverflow(minInt, minInt, &r), true);
QCOMPARE(qMulOverflow(maxInt, int(1), &r), false);
QCOMPARE(qMulOverflow(maxInt, int(-1), &r), false);
QCOMPARE(qMulOverflow(maxInt, int(2), &r), true);
QCOMPARE(qMulOverflow(maxInt, maxInt, &r), true);
}
QTEST_APPLESS_MAIN(tst_QNumeric)