From f98ee77cd3e9964b995d063345a895e537bc1157 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sun, 17 Jun 2018 20:09:39 +0200 Subject: QByteArray: toInt() and toDouble() ignore surrounding whitespaces [ChangeLog][QtCore][QByteArray] QByteArray::toInt(), QByteArray::toDouble() and the other number conversion functions now ignore leading and trailing whitespaces, as their QString counterparts already did. For consistency reasons, the same behavior was added to qEnvironmentVariableIntValue() also. Task-number: QTBUG-66187 Change-Id: I8b5e478ea8577b811d969286ea9e269f539c1ea4 Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne --- src/corelib/tools/qlocale.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools/qlocale.cpp') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index e70630eb12..3997652437 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3645,6 +3645,11 @@ qlonglong QLocaleData::bytearrayToLongLong(const char *num, int base, bool *ok) return 0; } + if (*endptr != '\0') { + while (ascii_isspace(*endptr)) + ++endptr; + } + if (*endptr != '\0') { // we stopped at a non-digit character after converting some digits if (ok != 0) @@ -3663,12 +3668,23 @@ qulonglong QLocaleData::bytearrayToUnsLongLong(const char *num, int base, bool * const char *endptr; qulonglong l = qstrtoull(num, &endptr, base, &_ok); - if (!_ok || *endptr != '\0') { + if (!_ok) { if (ok != 0) *ok = false; return 0; } + if (*endptr != '\0') { + while (ascii_isspace(*endptr)) + ++endptr; + } + + if (*endptr != '\0') { + if (ok != nullptr) + *ok = false; + return 0; + } + if (ok != 0) *ok = true; return l; -- cgit v1.2.3