sal/rtl/math.cxx |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

New commits:
commit 699c1115788145e7e02fc376aead663e974e3524
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Wed Nov 25 13:54:31 2020 +0100
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Tue Dec 8 15:20:35 2020 +0100

    Related: tdf#136272 accept 1.79769313486232e+308 as DBL_MAX
    
    This does not solve writing the badly rounded value, which still
    has to be fixed, but at least be able to read/convert it back as
    double max value.
    
    This is not even used in the bug scenario because the "fake"
    condition in that number format is discarded anyway because it was
    only written to satisfy ODF, but it helps in case a
    1.7976931348623157e+308 value was entered/used on purpose.
    
    Change-Id: I413dd93d5a3c4df609fd42a3133d6d82c34afff0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106586
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit ee2cc952eeb5385ee37485c822d7ad7abd8fb989)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106613
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
    Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index b01253c70dfa..9c32cff30f2f 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -976,7 +976,26 @@ double stringToDouble(CharT const * pBegin, CharT const * 
pEnd,
             errno = 0;
             fVal = strtod_nolocale(buf, &pCharParseEnd);
             if (errno == ERANGE)
-                eStatus = rtl_math_ConversionStatus_OutOfRange;
+            {
+                // Check for the dreaded rounded to 15 digits max value
+                // 1.79769313486232e+308 for 1.7976931348623157e+308 we wrote
+                // everywhere, accept with or without plus sign in exponent.
+                const char* b = buf;
+                if (b[0] == '-')
+                    ++b;
+                if (((pCharParseEnd - b == 21) || (pCharParseEnd - b == 20))
+                        && !strncmp( b, "1.79769313486232", 16)
+                        && (b[16] == 'e' || b[16] == 'E')
+                        && (((pCharParseEnd - b == 21) && !strncmp( b+17, 
"+308", 4))
+                         || ((pCharParseEnd - b == 20) && !strncmp( b+17, 
"308", 3))))
+                {
+                    fVal = (buf < b) ? -DBL_MAX : DBL_MAX;
+                }
+                else
+                {
+                    eStatus = rtl_math_ConversionStatus_OutOfRange;
+                }
+            }
             p = bufmap[pCharParseEnd - buf];
             bSign = false;
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to