diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-07-08 15:36:29 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-07-09 09:48:40 +0200 |
commit | 9d27a44e8b79373573ea038d8a44874785036fd3 (patch) | |
tree | a6c0ea89efd9acc5924324ba296b0b72d56ea24b /sal | |
parent | a5606b69333a6f13cc8eec8f6f47db1a2fb5fb0c (diff) |
Do not support +/-NaN with an explicit sign
The code accepting "NaN" had been introduced with
92dafe9862d693ce9d79269627c3e6832422874e "dba33h: #i112652#: rtl/math.h:
string<->double conversion and XMLSchema-2: [...] rtl_math_stringToDouble and
rtl_math_uStringToDouble support XMLSchema-2 values in addition to deprecated
previously supported values." The "XMLSchema-2" mentioned in that commit and in
the corresponding <https://bz.apache.org/ooo/show_bug.cgi?id=112652> "ORB:
report builder not handle correctly NULL values" presumably references
<https://www.w3.org/TR/xmlschema-2/> "XML Schema Part 2: Datatypes Second
Edition", where section "3.2.5 double" only supports "NaN" without a "+" or a
"-" sign in the lexical representation. So stop accepting those.
(I came across this in the context of 2b2b6405161025678f91a5625e50d0b414597368
"Reliably generate positive or negative NaN again", wondering whether this code
should be updated too. But then decided that it is probably best not to allow
that non-standard signed NaN notation for this case, and just keep producing for
the "NaN" representation whatever std::numeric_limits<double>::quiet_NaN
produces.)
Change-Id: I035e78ca36240317f72f117d2b456fc474d8c08a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118647
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 14 | ||||
-rw-r--r-- | sal/rtl/math.cxx | 7 |
2 files changed, 20 insertions, 1 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index f4df71e78ac3..f6ab314fbd21 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -75,6 +75,20 @@ public: CPPUNIT_ASSERT(std::isnan(res)); res = rtl::math::stringToDouble( + OUString("+NaN"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + res = rtl::math::stringToDouble( + OUString("-NaN"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + res = rtl::math::stringToDouble( OUString("+1.#NAN"), '.', ',', &status, &end); CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index 5d4ed6061f97..feb3a2b1852d 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -835,16 +835,21 @@ double stringToDouble(CharT const * pBegin, CharT const * pEnd, } bool bSign; + bool explicitSign = false; if (p0 != pEnd && *p0 == CharT('-')) { bSign = true; + explicitSign = true; ++p0; } else { bSign = false; if (p0 != pEnd && *p0 == CharT('+')) + { + explicitSign = true; ++p0; + } } CharT const * p = p0; @@ -853,7 +858,7 @@ double stringToDouble(CharT const * pBegin, CharT const * pEnd, // #i112652# XMLSchema-2 if ((pEnd - p) >= 3) { - if ((CharT('N') == p[0]) && (CharT('a') == p[1]) + if (!explicitSign && (CharT('N') == p[0]) && (CharT('a') == p[1]) && (CharT('N') == p[2])) { p += 3; |