diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-18 14:26:58 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-24 10:06:53 +0100 |
commit | 6c435e5dd41177308f22ba4b55931b2c463cb0d8 (patch) | |
tree | cd607b37ec21b3c6bb2bfa5862c0e4bc2dc4d44b /src/corelib/text/qlocale.cpp | |
parent | a036bd1746a8be9d8d9f15d70f8d0258d1a4fc46 (diff) |
Restore end-of-parse reporting to qstrntod()
Rework QSimpleParsedNumber to store a qsizetype whose sign serves as
ok flag (positive is ok, zero and negative are not) and magnitude is
the number of characters used. This replaces an endptr that was set to
null to indicate !ok, but that deprived us of end-of-parse
information, which is needed for number-parsing. In particular, JS's
parsing of numbers accepts overflow (where qstrntod() flags it as
invalid) as infinity; so qstrntod() does need to say how long the
overflowing (but JS-valid, none the less) number-text was.
Modify all callers of functions using this (recently-introduced) type
and add tests that fail without this fix.
Fixes: QTBUG-108628
Change-Id: I416cd213e1fb8101b1af5a6d43615b970a5db9b4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 97d84eac4e..23534cbb58 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -4145,20 +4145,20 @@ qulonglong QLocaleData::stringToUnsLongLong(QStringView str, int base, bool *ok, qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *ok) { - auto [l, endptr] = qstrntoll(num.data(), num.size(), base); - if (!endptr) { + const qsizetype len = num.size(); + auto [l, used] = qstrntoll(num.data(), len, base); + if (used <= 0) { if (ok != nullptr) *ok = false; return 0; } - const char *const stop = num.end(); - if (endptr < stop && *endptr != '\0') { - while (endptr < stop && ascii_isspace(*endptr)) - ++endptr; + if (used < len && num[used] != '\0') { + while (used < len && ascii_isspace(num[used])) + ++used; } - if (endptr < stop && *endptr != '\0') { + if (used < len && num[used] != '\0') { // we stopped at a non-digit character after converting some digits if (ok != nullptr) *ok = false; @@ -4172,20 +4172,20 @@ qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *o qulonglong QLocaleData::bytearrayToUnsLongLong(QByteArrayView num, int base, bool *ok) { - auto [l, endptr] = qstrntoull(num.data(), num.size(), base); - if (!endptr) { + const qsizetype len = num.size(); + auto [l, used] = qstrntoull(num.data(), len, base); + if (used <= 0) { if (ok != nullptr) *ok = false; return 0; } - const char *const stop = num.end(); - if (endptr < stop && *endptr != '\0') { - while (endptr < stop && ascii_isspace(*endptr)) - ++endptr; + if (used < len && num[used] != '\0') { + while (used < len && ascii_isspace(num[used])) + ++used; } - if (endptr < stop && *endptr != '\0') { + if (used < len && num[used] != '\0') { if (ok != nullptr) *ok = false; return 0; |