[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - basic/qa sal/qa sal/rtl

Eike Rathke erack at redhat.com
Tue Oct 15 09:03:18 PDT 2013


 basic/qa/cppunit/test_scanner.cxx |    4 +++-
 sal/qa/rtl/math/test-rtl-math.cxx |   12 ++++++++++++
 sal/rtl/math.cxx                  |    6 ++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit d8b9d9e84ef2e18bda11d51f6c9eb1fe4f1fb791
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Oct 14 14:55:23 2013 +0200

    resolved fdo#70319 exponent must be followed by at least one digit
    
    (cherry picked from commit f20feba4c43c34fd2ee05b4658b0de0248c08eb9)
    
    work around crappy SbiScanner::NextSym(), fdo#70319
    
    just to make test not fail that was wrong anyway
    
    (cherry picked from commit 472ad8ba7ef99982025b37aba562f2135ca8a999)
    
    Change-Id: Icdd22fa0f1efcdd18cfea7cb48e1cbf2cf8d3533
    Reviewed-on: https://gerrit.libreoffice.org/6241
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Tested-by: Michael Stahl <mstahl at redhat.com>

diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx
index 9c8d388..acf740fb 100644
--- a/basic/qa/cppunit/test_scanner.cxx
+++ b/basic/qa/cppunit/test_scanner.cxx
@@ -647,6 +647,8 @@ namespace
     CPPUNIT_ASSERT(symbols[1].text == cr);
     CPPUNIT_ASSERT(errors == 0);
 
+    /* FIXME: SbiScanner::NextSym() is total crap, the result of scanning
+     * "12e++3" should be something different than this.. */
     symbols = getSymbols(source12, errors);
     CPPUNIT_ASSERT(symbols.size() == 4);
     CPPUNIT_ASSERT(symbols[0].number == 12);
@@ -655,7 +657,7 @@ namespace
     CPPUNIT_ASSERT(symbols[2].number == 3);
     CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER);
     CPPUNIT_ASSERT(symbols[3].text == cr);
-    CPPUNIT_ASSERT(errors == 0);
+    CPPUNIT_ASSERT(errors == 1);
 
     symbols = getSymbols(source13, errors);
     CPPUNIT_ASSERT(symbols.size() == 2);
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx
index c156c37..3ebdb15 100644
--- a/sal/qa/rtl/math/test-rtl-math.cxx
+++ b/sal/qa/rtl/math/test-rtl-math.cxx
@@ -72,9 +72,21 @@ public:
         CPPUNIT_ASSERT_EQUAL(0.0, res);
     }
 
+    void test_stringToDouble_exponent_without_digit() {
+        rtl_math_ConversionStatus status;
+        sal_Int32 end;
+        double res = rtl::math::stringToDouble(
+            rtl::OUString("1e"),
+            sal_Unicode('.'), sal_Unicode(','), &status, &end);
+        CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(RTL_CONSTASCII_LENGTH("1")), end);
+        CPPUNIT_ASSERT_EQUAL(1.0, res);
+    }
+
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(test_stringToDouble_good);
     CPPUNIT_TEST(test_stringToDouble_bad);
+    CPPUNIT_TEST(test_stringToDouble_exponent_without_digit);
     CPPUNIT_TEST_SUITE_END();
 };
 
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index 590ea0e..f66039a 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -799,6 +799,7 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd,
         // Exponent
         if (p != p0 && p != pEnd && (*p == CharT('E') || *p == CharT('e')))
         {
+            CharT const * const pExponent = p;
             ++p;
             bool bExpSign;
             if (p != pEnd && *p == CharT('-'))
@@ -812,6 +813,7 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd,
                 if (p != pEnd && *p == CharT('+'))
                     ++p;
             }
+            CharT const * const pFirstExpDigit = p;
             if ( fVal == 0.0 )
             {   // no matter what follows, zero stays zero, but carry on the
                 // offset
@@ -857,6 +859,10 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd,
                     else
                         fVal = rtl::math::pow10Exp( fVal, nExp );  // normal
                 }
+                else if (p == pFirstExpDigit)
+                {   // no digits in exponent, reset end of scan
+                    p = pExponent;
+                }
             }
         }
         else if (p - p0 == 2 && p != pEnd && p[0] == CharT('#')


More information about the Libreoffice-commits mailing list