From b209f943d2611fa4ac2dd9c64b1a014182b59a3d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 20 Mar 2023 12:33:02 +0100 Subject: [PATCH] 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. Pick-to: 6.6 6.5 Change-Id: Ic0f7c92f7c47923317109e8a9dc06fa66bdff2c2 Reviewed-by: Fabian Kosmale --- src/corelib/io/qresource.cpp | 2 +- src/corelib/io/qurlidna.cpp | 10 +-- .../serialization/qcborstreamreader.cpp | 4 +- src/corelib/serialization/qcborvalue.cpp | 4 +- src/corelib/time/qdatetime.cpp | 26 +++---- src/corelib/time/qlocaltime.cpp | 8 +- src/corelib/time/qtimezoneprivate.cpp | 6 +- src/corelib/time/qtimezoneprivate_win.cpp | 6 +- src/corelib/tools/qarraydata.cpp | 6 +- src/gui/image/qimage.cpp | 2 +- src/gui/image/qimage_p.h | 8 +- src/gui/util/qastchandler.cpp | 6 +- .../corelib/global/qnumeric/tst_qnumeric.cpp | 76 +++++++++---------- 13 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index a3237f25bc0..56394911256 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -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; } diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp index da592eb81b1..bb14e1cdf7d 100644 --- a/src/corelib/io/qurlidna.cpp +++ b/src/corelib/io/qurlidna.cpp @@ -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(m - n, h + 1, &tmp) || add_overflow(delta, tmp, &delta)) { + if (qMulOverflow(m - n, h + 1, &tmp) || qAddOverflow(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(delta, 1, &delta)) { + if (qAddOverflow(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(digit, w, &tmp) || add_overflow(i, tmp, &i)) + if (qMulOverflow(digit, w, &tmp) || qAddOverflow(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(w, base - t, &w)) + if (qMulOverflow(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(n, i / (outputLength + 1), &n)) + if (qAddOverflow(n, i / (outputLength + 1), &n)) return QString(); // allow the deltas to wrap around diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp index 65ba253ed96..8f999c71184 100644 --- a/src/corelib/serialization/qcborstreamreader.cpp +++ b/src/corelib/serialization/qcborstreamreader.cpp @@ -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::max()) - || add_overflow(offset, len, &total)) + || qAddOverflow(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(oldSize, toRead, &newSize)) { + if (qAddOverflow(oldSize, toRead, &newSize)) { handleError(CborErrorDataTooLarge); return -1; } diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index c10f412ea99..2a01d7cfb5d 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -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::max() / 1000; ok = (e.value > -Limit && e.value < Limit); diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 55c9f120a16..cd4cdf7d5e8 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -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(), sumMillis) - || add_overflow(*sumMillis, millisInDay, sumMillis); + return qMulOverflow(days, std::integral_constant(), 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(), + || qMulOverflow(jd - *fakeJd, std::integral_constant(), &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; 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(), &msecs)) { + if (!qMulOverflow(secs, std::integral_constant(), &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(), &msecs)) + if (qMulOverflow(s, std::integral_constant(), &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 { diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 145da917232..e059b30bcfa 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -176,15 +176,15 @@ inline std::optional 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 diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index 8871add25d0..6f0b51f8dd5 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -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::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 { diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 7c5249ef5b5..b1abcb7a970 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -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(), &dayms) - || add_overflow(dayms, msInDay, msecs); + return qMulOverflow(daySinceEpoch, std::integral_constant(), &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); } diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index b1634d61b52..433385ade39 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -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; } diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 4aff92ac80d..71367f6d7b5 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -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(bpl, height, ¶ms.totalSize)) + if (qMulOverflow(bpl, height, ¶ms.totalSize)) return nullptr; } diff --git a/src/gui/image/qimage_p.h b/src/gui/image/qimage_p.h index ba22c99ed7e..27b32ca2003 100644 --- a/src/gui/image/qimage_p.h +++ b/src/gui/image/qimage_p.h @@ -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 diff --git a/src/gui/util/qastchandler.cpp b/src/gui/util/qastchandler.cpp index f5c1d84f91f..ec8b92f5571 100644 --- a/src/gui/util/qastchandler.cpp +++ b/src/gui/util/qastchandler.cpp @@ -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)); diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index 03acf5c0745..2fffedf4923 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -434,33 +434,33 @@ template 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()), &r), false); \ + QCOMPARE(qAddOverflow(Int(v1), (std::integral_constant()), &r), false); \ QCOMPARE(r, Int(expected)); \ - QCOMPARE(add_overflow(Int(v1), &r), false); \ + QCOMPARE(qAddOverflow(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()), &r), true); \ - QCOMPARE(add_overflow(Int(v1), &r), true); \ + QCOMPARE(qAddOverflow(Int(v1), Int(v2), &r), true); \ + QCOMPARE(qAddOverflow(Int(v1), (std::integral_constant()), &r), true); \ + QCOMPARE(qAddOverflow(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()), &r), false); \ + QCOMPARE(qSubOverflow(Int(v1), (std::integral_constant()), &r), false); \ QCOMPARE(r, Int(expected)); \ - QCOMPARE(sub_overflow(Int(v1), &r), false); \ + QCOMPARE(qSubOverflow(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()), &r), true); \ - QCOMPARE(sub_overflow(Int(v1), &r), true); \ + QCOMPARE(qSubOverflow(Int(v1), Int(v2), &r), true); \ + QCOMPARE(qSubOverflow(Int(v1), (std::integral_constant()), &r), true); \ + QCOMPARE(qSubOverflow(Int(v1), &r), true); \ } while (false) // basic values @@ -611,18 +611,18 @@ template 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()), &r), false); \ + QCOMPARE(qMulOverflow(Int(v1), (std::integral_constant()), &r), false); \ QCOMPARE(r, Int(expected)); \ - QCOMPARE(mul_overflow(Int(v1), &r), false); \ + QCOMPARE(qMulOverflow(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()), &r), true); \ - QCOMPARE(mul_overflow(Int(v1), &r), true); \ + QCOMPARE(qMulOverflow(Int(v1), Int(v2), &r), true); \ + QCOMPARE(qMulOverflow(Int(v1), (std::integral_constant()), &r), true); \ + QCOMPARE(qMulOverflow(Int(v1), &r), true); \ } while (false); // basic multiplications @@ -723,28 +723,28 @@ void tst_QNumeric::signedOverflow() const int maxInt = std::numeric_limits::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)