[poppler] goo/GooCheckedOps.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jan 17 23:36:52 UTC 2021


 goo/GooCheckedOps.h |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

New commits:
commit 7c6a8b90ebaf2d5aaad8d2643601e59fa2cc4a0e
Author: Albert Astals Cid <aacid at kde.org>
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 <adam.reichold at t-online.de>
 // Copyright (C) 2019 LE GARREC Vincent <legarrec.vincent at gmail.com>
-// Copyright (C) 2019, 2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2019-2021 Albert Astals Cid <aacid at kde.org>
 //
 //========================================================================
 
@@ -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)
 {


More information about the poppler mailing list