From 6c435e5dd41177308f22ba4b55931b2c463cb0d8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 18 Nov 2022 14:26:58 +0100 Subject: 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 --- src/corelib/tools/qversionnumber.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qversionnumber.cpp') diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index f44d5e4e8c..dcb2a3ad64 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -409,12 +409,12 @@ static QVersionNumber from_string(QLatin1StringView string, qsizetype *suffixInd do { // parsing as unsigned so a minus sign is rejected - auto [value, end] = qstrntoull(start, endOfString - start, 10); - if (!end || value > qulonglong(std::numeric_limits::max())) + auto [value, used] = qstrntoull(start, endOfString - start, 10); + if (used <= 0 || value > qulonglong(std::numeric_limits::max())) break; seg.append(int(value)); - start = end + 1; - lastGoodEnd = end; + start += used + 1; + lastGoodEnd = start - 1; } while (start < endOfString && *lastGoodEnd == '.'); if (suffixIndex) -- cgit v1.2.3