summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-10-26 10:45:08 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-10-27 12:28:30 +0200
commit7ee3953ce53f8259c5058a32bad6ad76adbf7151 (patch)
treee1aab3047d0e0147c5bc2bf2be8cb78637e9537a /include
parent6b760dc4bbb496496982d6d7aaa3701903bc3c11 (diff)
ofz#3819 Integer-overflow
Change-Id: Ic45692152b039c0ee2f5659d7739c3a2517c5e83 Reviewed-on: https://gerrit.libreoffice.org/43876 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/safeint.hxx9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 47baccf067f8..56175edb3bbe 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -56,6 +56,15 @@ typename std::enable_if<std::is_unsigned<T>::value, T>::type saturating_add(
}
}
+template<typename T> inline
+typename std::enable_if<std::is_signed<T>::value, T>::type saturating_toggle_sign(
+ T a)
+{
+ if (a == std::numeric_limits<T>::min())
+ return std::numeric_limits<T>::max();
+ return a * -1;
+}
+
#if defined(_MSC_VER)
template<typename T> inline bool checked_multiply(T a, T b, T& result)