[poppler] goo/GooCheckedOps.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 1 10:29:55 UTC 2021


 goo/GooCheckedOps.h |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

New commits:
commit f4364adf48b0217297021beed3eaf59a64ec5f45
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Dec 1 11:23:50 2021 +0100

    Make checkedMultiply work for long long in MSVC

diff --git a/goo/GooCheckedOps.h b/goo/GooCheckedOps.h
index 2bf13d01..a87a3e68 100644
--- a/goo/GooCheckedOps.h
+++ b/goo/GooCheckedOps.h
@@ -87,6 +87,21 @@ inline bool checkedMultiply(T x, T y, T *z)
 #endif
 }
 
+template<>
+inline bool checkedMultiply<long long>(long long x, long long y, long long *z)
+{
+#if __GNUC__ >= 5 || __has_builtin(__builtin_mul_overflow)
+    return __builtin_mul_overflow(x, y, z);
+#else
+    if (x != 0 && (std::numeric_limits<long long>::max)() / x < y) {
+        return true;
+    }
+
+    *z = x * y;
+    return false;
+#endif
+}
+
 template<typename T>
 inline T safeAverage(T a, T b)
 {


More information about the poppler mailing list