[Libreoffice-commits] core.git: 3 commits - sc/source

Eike Rathke erack at redhat.com
Fri Jul 1 09:48:04 UTC 2016


 sc/source/core/tool/interpr4.cxx |   84 ++++++++++++++++++++++++++-------------
 1 file changed, 57 insertions(+), 27 deletions(-)

New commits:
commit 835fa9bd687518f44465cb22348a13984cdf779d
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jul 1 11:39:19 2016 +0200

    no need to check twice
    
    Change-Id: Iad2942851fced632c0c662bf754b1d687740105c

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index f57a970..9245ff7 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -2097,13 +2097,22 @@ sal_Int32 ScInterpreter::GetInt32()
 {
     double fVal = GetDouble();
     if (fVal > 0.0)
+    {
         fVal = rtl::math::approxFloor( fVal);
+        if (fVal > SAL_MAX_INT32)
+        {
+            SetError( errIllegalArgument);
+            return SAL_MAX_INT32;
+        }
+    }
     else if (fVal < 0.0)
-        fVal = rtl::math::approxCeil( fVal);
-    if (fVal < SAL_MIN_INT32 || fVal > SAL_MAX_INT32)
     {
-        SetError( errIllegalArgument);
-        return SAL_MAX_INT32;
+        fVal = rtl::math::approxCeil( fVal);
+        if (fVal < SAL_MIN_INT32)
+        {
+            SetError( errIllegalArgument);
+            return SAL_MAX_INT32;
+        }
     }
     return static_cast<sal_Int32>(fVal);
 }
@@ -2112,13 +2121,22 @@ sal_Int32 ScInterpreter::GetInt32WithDefault( sal_Int32 nDefault )
 {
     double fVal = GetDoubleWithDefault( nDefault);
     if (fVal > 0.0)
+    {
         fVal = rtl::math::approxFloor( fVal);
+        if (fVal > SAL_MAX_INT32)
+        {
+            SetError( errIllegalArgument);
+            return SAL_MAX_INT32;
+        }
+    }
     else if (fVal < 0.0)
-        fVal = rtl::math::approxCeil( fVal);
-    if (fVal < SAL_MIN_INT32 || fVal > SAL_MAX_INT32)
     {
-        SetError( errIllegalArgument);
-        return SAL_MAX_INT32;
+        fVal = rtl::math::approxCeil( fVal);
+        if (fVal < SAL_MIN_INT32)
+        {
+            SetError( errIllegalArgument);
+            return SAL_MAX_INT32;
+        }
     }
     return static_cast<sal_Int32>(fVal);
 }
@@ -2127,13 +2145,22 @@ sal_Int16 ScInterpreter::GetInt16()
 {
     double fVal = GetDouble();
     if (fVal > 0.0)
+    {
         fVal = rtl::math::approxFloor( fVal);
+        if (fVal > SAL_MAX_INT16)
+        {
+            SetError( errIllegalArgument);
+            return SAL_MAX_INT16;
+        }
+    }
     else if (fVal < 0.0)
-        fVal = rtl::math::approxCeil( fVal);
-    if (fVal < SAL_MIN_INT16 || fVal > SAL_MAX_INT16)
     {
-        SetError( errIllegalArgument);
-        return SAL_MAX_INT16;
+        fVal = rtl::math::approxCeil( fVal);
+        if (fVal < SAL_MIN_INT16)
+        {
+            SetError( errIllegalArgument);
+            return SAL_MAX_INT16;
+        }
     }
     return static_cast<sal_Int16>(fVal);
 }
commit f45a78ac585b847c64c4bb78436f895b243ca2f6
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jul 1 11:27:24 2016 +0200

    use GetInt32() for integer Add-In parameters
    
    Change-Id: Id62acb1800b3a302d62900699a01d1a5cdf1ab56

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index dd05982..f57a970 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -2639,13 +2639,9 @@ void ScInterpreter::ScExternal()
             {
                 case SC_ADDINARG_INTEGER:
                     {
-                        double fVal = GetDouble();
-                        double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
-                                                      ::rtl::math::approxCeil( fVal );
-                        if ( fInt >= LONG_MIN && fInt <= LONG_MAX )
-                            aParam <<= (sal_Int32)fInt;
-                        else
-                            SetError(errIllegalArgument);
+                        sal_Int32 nVal = GetInt32();
+                        if (!nGlobalError)
+                            aParam <<= nVal;
                     }
                     break;
 
@@ -2664,18 +2660,13 @@ void ScInterpreter::ScExternal()
                         case svString:
                         case svSingleRef:
                             {
-                                double fVal = GetDouble();
-                                double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
-                                                              ::rtl::math::approxCeil( fVal );
-                                if ( fInt >= LONG_MIN && fInt <= LONG_MAX )
+                                sal_Int32 nVal = GetInt32();
+                                if (!nGlobalError)
                                 {
-                                    sal_Int32 nIntVal = (long)fInt;
-                                    uno::Sequence<sal_Int32> aInner( &nIntVal, 1 );
+                                    uno::Sequence<sal_Int32> aInner( &nVal, 1 );
                                     uno::Sequence< uno::Sequence<sal_Int32> > aOuter( &aInner, 1 );
                                     aParam <<= aOuter;
                                 }
-                                else
-                                    SetError(errIllegalArgument);
                             }
                             break;
                         case svDoubleRef:
commit 415cd81d90aa5dd4f9a5d914fabd4c2371f53e4c
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jul 1 11:01:10 2016 +0200

    let GetInt*() truncate to integer towards 0
    
    like it should always had been the case ...
    
    Change-Id: I75b9e71bbaad5e356a45b416a3b42dc4becec801

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 1421f87..dd05982 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -2095,7 +2095,11 @@ double ScInterpreter::GetDoubleWithDefault(double nDefault)
 
 sal_Int32 ScInterpreter::GetInt32()
 {
-    double fVal = rtl::math::approxFloor( GetDouble());
+    double fVal = GetDouble();
+    if (fVal > 0.0)
+        fVal = rtl::math::approxFloor( fVal);
+    else if (fVal < 0.0)
+        fVal = rtl::math::approxCeil( fVal);
     if (fVal < SAL_MIN_INT32 || fVal > SAL_MAX_INT32)
     {
         SetError( errIllegalArgument);
@@ -2106,7 +2110,11 @@ sal_Int32 ScInterpreter::GetInt32()
 
 sal_Int32 ScInterpreter::GetInt32WithDefault( sal_Int32 nDefault )
 {
-    double fVal = rtl::math::approxFloor( GetDoubleWithDefault( nDefault));
+    double fVal = GetDoubleWithDefault( nDefault);
+    if (fVal > 0.0)
+        fVal = rtl::math::approxFloor( fVal);
+    else if (fVal < 0.0)
+        fVal = rtl::math::approxCeil( fVal);
     if (fVal < SAL_MIN_INT32 || fVal > SAL_MAX_INT32)
     {
         SetError( errIllegalArgument);
@@ -2117,7 +2125,11 @@ sal_Int32 ScInterpreter::GetInt32WithDefault( sal_Int32 nDefault )
 
 sal_Int16 ScInterpreter::GetInt16()
 {
-    double fVal = rtl::math::approxFloor( GetDouble());
+    double fVal = GetDouble();
+    if (fVal > 0.0)
+        fVal = rtl::math::approxFloor( fVal);
+    else if (fVal < 0.0)
+        fVal = rtl::math::approxCeil( fVal);
     if (fVal < SAL_MIN_INT16 || fVal > SAL_MAX_INT16)
     {
         SetError( errIllegalArgument);


More information about the Libreoffice-commits mailing list