goo/GooCheckedOps.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
New commits: commit 7c6a8b90ebaf2d5aaad8d2643601e59fa2cc4a0e Author: Albert Astals Cid <[email protected]> Date: Mon Jan 18 00:13:08 2021 +0100 Make checkedAdd work for long long in MSVC diff --git a/goo/GooCheckedOps.h b/goo/GooCheckedOps.h index b3037aff..2bf13d01 100644 --- a/goo/GooCheckedOps.h +++ b/goo/GooCheckedOps.h @@ -6,7 +6,7 @@ // // Copyright (C) 2018 Adam Reichold <[email protected]> // Copyright (C) 2019 LE GARREC Vincent <[email protected]> -// Copyright (C) 2019, 2020 Albert Astals Cid <[email protected]> +// Copyright (C) 2019-2021 Albert Astals Cid <[email protected]> // //======================================================================== @@ -45,6 +45,26 @@ inline bool checkedAdd(T x, T y, T *z) #endif } +template<> +inline bool checkedAdd<long long>(long long x, long long y, long long *z) +{ +#if __GNUC__ >= 5 || __has_builtin(__builtin_add_overflow) + return __builtin_add_overflow(x, y, z); +#else + if (x > 0 && y > 0) { + if (x > (std::numeric_limits<long long>::max)() - y) { + return true; + } + } else if (x < 0 && y < 0) { + if (x < (std::numeric_limits<long long>::min)() - y) { + return true; + } + } + *z = x + y; + return false; +#endif +} + template<typename T> inline bool checkedSubtraction(T x, T y, T *z) { _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
