diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-02-22 08:53:13 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-02-22 20:12:29 +0000 |
commit | b727f2190fb4878aad5edf1536e875e1b75907ae (patch) | |
tree | e5eb647d82dff44d8a7ef5c8693885ba0b4850cc | |
parent | a87edb9ae97ca10cb651b004817ee4ba09159f8b (diff) |
Protect headers against min/max macros
... using the usual pattern, which, being idiomatic, doesn't need a
comment explaining it.
Pick-to: 6.3
Change-Id: Id6b12450495a18f89e1f83f2018b6218b03ff6a7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/global/qendian.h | 4 | ||||
-rw-r--r-- | src/corelib/global/qnumeric.h | 8 | ||||
-rw-r--r-- | src/corelib/global/qnumeric_p.h | 6 | ||||
-rw-r--r-- | src/corelib/global/qrandom.h | 8 | ||||
-rw-r--r-- | src/corelib/kernel/qdeadlinetimer.h | 2 | ||||
-rw-r--r-- | src/corelib/text/qlocale_p.h | 2 | ||||
-rw-r--r-- | src/corelib/time/qtimezoneprivate_p.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qoffsetstringarray_p.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbeventqueue.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qcombobox_p.h | 2 |
10 files changed, 23 insertions, 23 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 759b3b09ec..f6263a08d1 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -313,9 +313,9 @@ public: } static constexpr QSpecialInteger max() - { return QSpecialInteger(std::numeric_limits<T>::max()); } + { return QSpecialInteger((std::numeric_limits<T>::max)()); } static constexpr QSpecialInteger min() - { return QSpecialInteger(std::numeric_limits<T>::min()); } + { return QSpecialInteger((std::numeric_limits<T>::min)()); } }; template<typename T> diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h index 49d795902c..a40c95b637 100644 --- a/src/corelib/global/qnumeric.h +++ b/src/corelib/global/qnumeric.h @@ -219,7 +219,7 @@ qMulOverflow(T v1, T v2, T *r) typename LargerInt::Signed, typename LargerInt::Unsigned>; Larger lr = Larger(v1) * Larger(v2); *r = T(lr); - return lr > std::numeric_limits<T>::max() || lr < std::numeric_limits<T>::min(); + return lr > (std::numeric_limits<T>::max)() || lr < (std::numeric_limits<T>::min)(); } # if defined(Q_INTRINSIC_MUL_OVERFLOW64) @@ -324,15 +324,15 @@ template <typename T, T V2> bool qMulOverflow(T v1, std::integral_constant<T, V2 } else if constexpr (V2 == -1) { // multiplication by -1 is valid *except* for signed minimum values // (necessary to avoid diving min() by -1, which is an overflow) - if (v1 < 0 && v1 == std::numeric_limits<T>::min()) + if (v1 < 0 && v1 == (std::numeric_limits<T>::min)()) return true; *r = -v1; return false; } else { // For 64-bit multiplications on 32-bit platforms, let's instead compare v1 // against the bounds that would overflow. - constexpr T Highest = std::numeric_limits<T>::max() / V2; - constexpr T Lowest = std::numeric_limits<T>::min() / V2; + constexpr T Highest = (std::numeric_limits<T>::max)() / V2; + constexpr T Lowest = (std::numeric_limits<T>::min)() / V2; if constexpr (Highest > Lowest) { if (v1 > Highest || v1 < Lowest) return true; diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index b7af847673..f224f9848c 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -203,8 +203,8 @@ static inline bool convertDoubleTo(double v, T *value, bool allow_precision_upgr return false; } - constexpr T Tmin = std::numeric_limits<T>::min(); - constexpr T Tmax = std::numeric_limits<T>::max(); + constexpr T Tmin = (std::numeric_limits<T>::min)(); + constexpr T Tmax = (std::numeric_limits<T>::max)(); // The [conv.fpint] (7.10 Floating-integral conversions) section of the C++ // standard says only exact conversions are guaranteed. Converting @@ -295,7 +295,7 @@ static inline bool convertDoubleTo(double v, T *value, bool allow_precision_upgr return false; } else { using ST = typename std::make_signed<T>::type; - supremum = -2.0 * std::numeric_limits<ST>::min(); // -2 * (-2^63) = 2^64, exact (for T = quint64) + supremum = -2.0 * (std::numeric_limits<ST>::min)(); // -2 * (-2^63) = 2^64, exact (for T = quint64) v = fabs(v); } diff --git a/src/corelib/global/qrandom.h b/src/corelib/global/qrandom.h index aef2677c13..a44449d929 100644 --- a/src/corelib/global/qrandom.h +++ b/src/corelib/global/qrandom.h @@ -203,8 +203,8 @@ public: void seed(quint32 s = 1) { *this = { s }; } void seed(std::seed_seq &sseq) noexcept { *this = { sseq }; } Q_CORE_EXPORT void discard(unsigned long long z); - static constexpr result_type min() { return std::numeric_limits<result_type>::min(); } - static constexpr result_type max() { return std::numeric_limits<result_type>::max(); } + static constexpr result_type min() { return (std::numeric_limits<result_type>::min)(); } + static constexpr result_type max() { return (std::numeric_limits<result_type>::max)(); } static inline Q_DECL_CONST_FUNCTION QRandomGenerator *system(); static inline Q_DECL_CONST_FUNCTION QRandomGenerator *global(); @@ -277,8 +277,8 @@ public: QRandomGenerator::discard(z * 2); } - static constexpr result_type min() { return std::numeric_limits<result_type>::min(); } - static constexpr result_type max() { return std::numeric_limits<result_type>::max(); } + static constexpr result_type min() { return (std::numeric_limits<result_type>::min)(); } + static constexpr result_type max() { return (std::numeric_limits<result_type>::max)(); } static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 *system(); static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 *global(); static Q_CORE_EXPORT QRandomGenerator64 securelySeeded(); diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 32e7d2cde3..6bc6434551 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -66,7 +66,7 @@ public: constexpr QDeadlineTimer(Qt::TimerType type_ = Qt::CoarseTimer) noexcept : t1(0), t2(0), type(type_) {} constexpr QDeadlineTimer(ForeverConstant, Qt::TimerType type_ = Qt::CoarseTimer) noexcept - : t1(std::numeric_limits<qint64>::max()), t2(0), type(type_) {} + : t1((std::numeric_limits<qint64>::max)()), t2(0), type(type_) {} explicit QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) noexcept; void swap(QDeadlineTimer &other) noexcept diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index 5326831bb6..953de2673f 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -263,7 +263,7 @@ public: { if (qIsInf(d)) return float(d); - if (std::fabs(d) > std::numeric_limits<float>::max()) { + if (std::fabs(d) > (std::numeric_limits<float>::max)()) { if (ok) *ok = false; const float huge = std::numeric_limits<float>::infinity(); diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h index a436c87999..9472586fd9 100644 --- a/src/corelib/time/qtimezoneprivate_p.h +++ b/src/corelib/time/qtimezoneprivate_p.h @@ -137,10 +137,10 @@ public: virtual void serialize(QDataStream &ds) const; // Static Utility Methods - static inline qint64 maxMSecs() { return std::numeric_limits<qint64>::max(); } - static inline qint64 minMSecs() { return std::numeric_limits<qint64>::min() + 1; } - static inline qint64 invalidMSecs() { return std::numeric_limits<qint64>::min(); } - static inline qint64 invalidSeconds() { return std::numeric_limits<int>::min(); } + static inline qint64 maxMSecs() { return (std::numeric_limits<qint64>::max)(); } + static inline qint64 minMSecs() { return (std::numeric_limits<qint64>::min)() + 1; } + static inline qint64 invalidMSecs() { return (std::numeric_limits<qint64>::min)(); } + static inline qint64 invalidSeconds() { return (std::numeric_limits<int>::min)(); } static Data invalidData(); static QTimeZone::OffsetData invalidOffsetData(); static QTimeZone::OffsetData toOffsetData(const Data &data); diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h index 8bd7d79afb..3e4abf4bb5 100644 --- a/src/corelib/tools/qoffsetstringarray_p.h +++ b/src/corelib/tools/qoffsetstringarray_p.h @@ -117,9 +117,9 @@ static constexpr OO copyData(II input, qsizetype n, OO output) template <size_t Highest> constexpr auto minifyValue() { - if constexpr (Highest <= std::numeric_limits<quint8>::max()) { + if constexpr (Highest <= (std::numeric_limits<quint8>::max)()) { return quint8(Highest); - } else if constexpr (Highest <= std::numeric_limits<quint16>::max()) { + } else if constexpr (Highest <= (std::numeric_limits<quint16>::max)()) { return quint16(Highest); } else { // int is probably enough for everyone diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.h b/src/plugins/platforms/xcb/qxcbeventqueue.h index 10b6810014..a9d3e23b77 100644 --- a/src/plugins/platforms/xcb/qxcbeventqueue.h +++ b/src/plugins/platforms/xcb/qxcbeventqueue.h @@ -123,7 +123,7 @@ public: const QXcbEventNode *flushedTail() const { return m_flushedTail; } void waitForNewEvents(const QXcbEventNode *sinceFlushedTail, - unsigned long time = std::numeric_limits<unsigned long>::max()); + unsigned long time = (std::numeric_limits<unsigned long>::max)()); private: QXcbEventNode *qXcbEventNodeFactory(xcb_generic_event_t *event); diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index df3421692f..73d9e661f3 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -423,7 +423,7 @@ public: int minimumContentsLength = 0; int indexBeforeChange = -1; int maxVisibleItems = 10; - int maxCount = std::numeric_limits<int>::max(); + int maxCount = (std::numeric_limits<int>::max)(); int modelColumn = 0; int placeholderIndex = -1; bool shownOnce : 1; |