diff options
author | Eike Rathke <erack@redhat.com> | 2013-10-14 14:55:23 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-10-17 15:57:42 +0000 |
commit | d7eae616fcb80e1d77ea981cce363e1414fd5238 (patch) | |
tree | d8af4ec8454554feb142115d8489190edf5fee9f | |
parent | 4898ccc561af302db3b947f3a7b983e7f4c08566 (diff) |
resolved fdo#70319 exponent must be followed by at least one digit
Change-Id: Icdd22fa0f1efcdd18cfea7cb48e1cbf2cf8d3533
(cherry picked from commit f20feba4c43c34fd2ee05b4658b0de0248c08eb9)
Reviewed-on: https://gerrit.libreoffice.org/6242
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
(cherry picked from commit 2afaef576d0567e7137a439fc98804960cd7c17c)
Reviewed-on: https://gerrit.libreoffice.org/6269
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 12 | ||||
-rw-r--r-- | sal/rtl/source/math.cxx | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index 70e8107aa79b..8f6578cd791a 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/source/math.cxx b/sal/rtl/source/math.cxx index c0d93b6a85af..e5c44d561979 100644 --- a/sal/rtl/source/math.cxx +++ b/sal/rtl/source/math.cxx @@ -805,6 +805,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('-')) @@ -818,6 +819,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 @@ -863,6 +865,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('#') |