summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2018-06-17 20:09:39 +0200
committerAndré Hartmann <aha_1980@gmx.de>2018-07-07 19:58:18 +0000
commitf98ee77cd3e9964b995d063345a895e537bc1157 (patch)
tree25b4f05d5bf44a6a74ca2b7092d50df44c55e1f9 /src/corelib/global/qglobal.cpp
parent85472b6b02b42ea624e1c00a5fd38c0d2889a731 (diff)
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 <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 3fe91cae65..b52139d5a6 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -3442,7 +3442,27 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT
bool ok_ = true;
const char *endptr;
const qlonglong value = qstrtoll(buffer, &endptr, 0, &ok_);
- if (int(value) != value || *endptr != '\0') { // this is the check in QByteArray::toInt(), keep it in sync
+
+ // Keep the following checks in sync with QByteArray::toInt()
+ if (!ok_) {
+ if (ok)
+ *ok = false;
+ 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)
+ *ok = false;
+ return 0;
+ }
+
+ if (int(value) != value) {
if (ok)
*ok = false;
return 0;