[Libreoffice-commits] core.git: emfio/source include/o3tl

Caolán McNamara caolanm at redhat.com
Fri Oct 27 10:28:53 UTC 2017


 emfio/source/reader/mtftools.cxx |    5 +++--
 include/o3tl/safeint.hxx         |    9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

New commits:
commit 7ee3953ce53f8259c5058a32bad6ad76adbf7151
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Oct 26 10:45:08 2017 +0100

    ofz#3819 Integer-overflow
    
    Change-Id: Ic45692152b039c0ee2f5659d7739c3a2517c5e83
    Reviewed-on: https://gerrit.libreoffice.org/43876
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 349f686f4ea9..b6de61d1f6bc 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -514,8 +514,9 @@ namespace emfio
         // must later be made portable in SV (KA 1996-02-08)
         Size  aFontSize = ImplMap (rFont.GetFontSize(), false);
 
-        if( aFontSize.Height() < 0 )
-            aFontSize.Height() *= -1;
+        const auto nHeight = aFontSize.Height();
+        if (nHeight < 0)
+            aFontSize.Height() = o3tl::saturating_toggle_sign(nHeight);
 
         rFont.SetFontSize( aFontSize );
 
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)


More information about the Libreoffice-commits mailing list