summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-11-25 09:22:21 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-11-25 10:55:39 +0100
commit6aa02bdeaf3449a254871ce9f893d8353bf26a53 (patch)
tree9af4bdc95bc5439015d40e5dc75f2cb5210d8e26
parent95b4cfb1af9aefe3ff3aa151804f464388329c63 (diff)
QLocale: Have qstrntod() return end of parsed string also on underflow
Underflows should be treated the same as overflows. Fixes: QTBUG-108628 Change-Id: I23aa7bbe1d103778cefca08bd3e584e72f306583 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/corelib/text/qlocale_tools.cpp2
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp
index ac4c870802..a123714f7f 100644
--- a/src/corelib/text/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
@@ -354,7 +354,7 @@ QSimpleParsedNumber<double> qt_asciiToDouble(const char *num, qsizetype numLen,
for (int i = 0; i < processed; ++i) {
if (num[i] >= '1' && num[i] <= '9') {
// if a digit before any 'e' is not 0, then a non-zero number was intended.
- return {};
+ return {d, -processed};
} else if (num[i] == 'e' || num[i] == 'E') {
break;
}
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index 593b98dd60..11da627bd0 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -1250,6 +1250,10 @@ void tst_QLocale::strtod_data()
QTest::newRow("1e2000") << QString("1e2000") << qInf() << 6 << false;
QTest::newRow("-1e2000") << QString("-1e2000") << -qInf() << 7 << false;
+ // Underflow - fails but reports right length:
+ QTest::newRow("1e-2000") << QString("1e-2000") << 0.0 << 7 << false;
+ QTest::newRow("-1e-2000") << QString("-1e-2000") << 0.0 << 8 << false;
+
// starts with junk, fails
QTest::newRow("a0") << QString("a0") << 0.0 << 0 << false;
QTest::newRow("a0.") << QString("a0.") << 0.0 << 0 << false;
@@ -1285,6 +1289,10 @@ void tst_QLocale::strtod_data()
QTest::newRow("1e2000 cruft") << QString("1e2000 cruft") << qInf() << 6 << false;
QTest::newRow("-1e2000 cruft") << QString("-1e2000 cruft") << -qInf() << 7 << false;
+ // Underflow, ends with cruft - fails but reports right length:
+ QTest::newRow("1e-2000 cruft") << QString("1e-2000 cruft") << 0.0 << 7 << false;
+ QTest::newRow("-1e-2000 cruft") << QString("-1e-2000 cruft") << 0.0 << 8 << false;
+
// "0x" prefix, success but only for the "0" before "x"
QTest::newRow("0x0") << QString("0x0") << 0.0 << 1 << true;
QTest::newRow("0x0.") << QString("0x0.") << 0.0 << 1 << true;