Do not support +/-NaN with an explicit sign
The code accepting "NaN" had been introduced with92dafe9862"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 of2b2b640516"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>
This commit is contained in:
committed by
Michael Stahl
parent
a5606b6933
commit
9d27a44e8b
@@ -74,6 +74,20 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end);
|
||||
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);
|
||||
|
||||
+6
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user