diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2020-07-24 10:18:37 -0700 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-07-31 03:29:11 +0000 |
commit | caa40f57d4d9ccf22d728e486148d2be6b29e249 (patch) | |
tree | 4afc221bd8b2b950b3961f2f4a6b4714d9297ea3 /src/corelib/text/qlocale_tools.cpp | |
parent | 2ab4fe2ac84d0da84b489f9898d44ab77b78fd6b (diff) |
QLocale: update qt_asciiToDouble to use qsizetype
No need to change the output variable from int to qsizetype. That would
complicate the use of libdouble-conversion, which uses ints.
Change-Id: Iea47e0f8fc8b40378df7fffd1624bfdba1189d81
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qlocale_tools.cpp')
-rw-r--r-- | src/corelib/text/qlocale_tools.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp index 4e43d7d29b..cc34d3149a 100644 --- a/src/corelib/text/qlocale_tools.cpp +++ b/src/corelib/text/qlocale_tools.cpp @@ -278,7 +278,7 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision, cha --length; } -double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed, +double qt_asciiToDouble(const char *num, qsizetype numLen, bool &ok, int &processed, StrayCharacterMode strayCharMode) { auto string_equals = [](const char *needle, const char *haystack, qsizetype haystackLen) { @@ -329,7 +329,14 @@ double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed, | double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES; } double_conversion::StringToDoubleConverter conv(conv_flags, 0.0, qt_qnan(), nullptr, nullptr); - d = conv.StringToDouble(num, numLen, &processed); + if (int(numLen) != numLen) { + // a number over 2 GB in length is silly, just assume it isn't valid + ok = false; + processed = 0; + return 0.0; + } else { + d = conv.StringToDouble(num, numLen, &processed); + } if (!qIsFinite(d)) { ok = false; @@ -487,19 +494,12 @@ QString qulltoa(qulonglong number, int base, const QStringView zero) return QString(reinterpret_cast<QChar *>(p), end - p); } -double qstrtod(const char *s00, const char **se, bool *ok) -{ - const int len = static_cast<int>(strlen(s00)); - Q_ASSERT(len >= 0); - return qstrntod(s00, len, se, ok); -} - /*! \internal Converts the initial portion of the string pointed to by \a s00 to a double, using the 'C' locale. */ -double qstrntod(const char *s00, int len, const char **se, bool *ok) +double qstrntod(const char *s00, qsizetype len, const char **se, bool *ok) { int processed = 0; bool nonNullOk = false; |