summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/math/test-rtl-math.cxx12
-rw-r--r--sal/rtl/math.cxx6
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 c156c37b9393..3ebdb157d463 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 590ea0ee46b0..f66039a4a3ad 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('#')