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 /src/corelib/global/qnumeric.h | |
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>
Diffstat (limited to 'src/corelib/global/qnumeric.h')
-rw-r--r-- | src/corelib/global/qnumeric.h | 8 |
1 files changed, 4 insertions, 4 deletions
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; |