sal/qa/rtl/math/test-rtl-math.cxx |   14 ++++++++++++++
 sal/rtl/math.cxx                  |    7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

New commits:
commit 9d27a44e8b79373573ea038d8a44874785036fd3
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Thu Jul 8 15:36:29 2021 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Fri Jul 9 09:48:40 2021 +0200

    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 <[email protected]>

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
@@ -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);
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;
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to