[Libreoffice-commits] core.git: basic/source

Eike Rathke erack at redhat.com
Fri Apr 28 14:14:05 UTC 2017


 basic/source/runtime/methods.cxx |   88 ++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 42 deletions(-)

New commits:
commit d6fd4252bf248d2872c713a1d83817a2dc88a9d2
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Apr 28 16:12:54 2017 +0200

    Use invalid parameter error for malformed input, tdf#106956 follow-up
    
    ... instead of invalid procedure call.
    
    Change-Id: I812f4c7041db9a116e65a24afb85164b4dd498b6

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 1bb3a474bc60..f4e60a51b2ca 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -2051,58 +2051,62 @@ RTLFUNC(CDateFromIso)
     (void)pBasic;
     (void)bWrite;
 
-    do
+    if ( rPar.Count() == 2 )
     {
-        if ( rPar.Count() != 2 )
-            break;
-
-        OUString aStr = rPar.Get(1)->GetOUString();
-        const sal_Int32 nLen = aStr.getLength();
-        if (nLen != 8 && nLen != 10)
-            break;
-
-        OUString aYearStr, aMonthStr, aDayStr;
-        if (nLen == 8)
+        do
         {
-            // YYYYMMDD
-            if (!comphelper::string::isdigitAsciiString(aStr))
+            OUString aStr = rPar.Get(1)->GetOUString();
+            const sal_Int32 nLen = aStr.getLength();
+            if (nLen != 8 && nLen != 10)
                 break;
 
-            aYearStr  = aStr.copy( 0, 4 );
-            aMonthStr = aStr.copy( 4, 2 );
-            aDayStr   = aStr.copy( 6, 2 );
-        }
-        else
-        {
-            // YYYY-MM-DD
-            const sal_Int32 nSep1 = aStr.indexOf('-');
-            if (nSep1 != 4)
-                break;
-            const sal_Int32 nSep2 = aStr.indexOf('-', nSep1+1);
-            if (nSep2 != 7)
-                break;
+            OUString aYearStr, aMonthStr, aDayStr;
+            if (nLen == 8)
+            {
+                // YYYYMMDD
+                if (!comphelper::string::isdigitAsciiString(aStr))
+                    break;
 
-            aYearStr  = aStr.copy( 0, 4 );
-            aMonthStr = aStr.copy( 5, 2 );
-            aDayStr   = aStr.copy( 8, 2 );
-            if (    !comphelper::string::isdigitAsciiString(aYearStr) ||
-                    !comphelper::string::isdigitAsciiString(aMonthStr) ||
-                    !comphelper::string::isdigitAsciiString(aDayStr))
+                aYearStr  = aStr.copy( 0, 4 );
+                aMonthStr = aStr.copy( 4, 2 );
+                aDayStr   = aStr.copy( 6, 2 );
+            }
+            else
+            {
+                // YYYY-MM-DD
+                const sal_Int32 nSep1 = aStr.indexOf('-');
+                if (nSep1 != 4)
+                    break;
+                const sal_Int32 nSep2 = aStr.indexOf('-', nSep1+1);
+                if (nSep2 != 7)
+                    break;
+
+                aYearStr  = aStr.copy( 0, 4 );
+                aMonthStr = aStr.copy( 5, 2 );
+                aDayStr   = aStr.copy( 8, 2 );
+                if (    !comphelper::string::isdigitAsciiString(aYearStr) ||
+                        !comphelper::string::isdigitAsciiString(aMonthStr) ||
+                        !comphelper::string::isdigitAsciiString(aDayStr))
+                    break;
+            }
+
+            double dDate;
+            if (!implDateSerial( (sal_Int16)aYearStr.toInt32(),
+                        (sal_Int16)aMonthStr.toInt32(), (sal_Int16)aDayStr.toInt32(), dDate ))
                 break;
-        }
 
-        double dDate;
-        if (!implDateSerial( (sal_Int16)aYearStr.toInt32(),
-                    (sal_Int16)aMonthStr.toInt32(), (sal_Int16)aDayStr.toInt32(), dDate ))
-            break;
+            rPar.Get(0)->PutDate( dDate );
 
-        rPar.Get(0)->PutDate( dDate );
+            return;
+        }
+        while (false);
 
-        return;
+        SbxBase::SetError( ERRCODE_SBX_BAD_PARAMETER );
+    }
+    else
+    {
+        StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
     }
-    while (false);
-
-    StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
 }
 
 RTLFUNC(DateSerial)


More information about the Libreoffice-commits mailing list