diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-27 15:25:26 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-30 17:46:00 +0200 |
commit | 7d33779a795afb54af1a96c0da93b532f9db3ba2 (patch) | |
tree | a760a2777d752fba7f91135ae7b80d37750d5745 /src/corelib/global | |
parent | 5644af6f8a800a1516360a42ba4c1a8dc61fc516 (diff) |
Convert various callers of strtou?ll() to call strntou?ll()
Where size is known or can readily be determined.
Change-Id: I442e7ebb3757fdbf7d021a15e19aeba533b590a5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 2a659e4172..e613266d7b 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3529,6 +3529,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept (std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit; const auto locker = qt_scoped_lock(environmentMutex); + size_t size; #ifdef Q_CC_MSVC // we provide a buffer that can hold any int value: char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-' @@ -3538,9 +3539,10 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept *ok = false; return 0; } + size = strlen(buffer); #else const char * const buffer = ::getenv(varName); - if (!buffer || strlen(buffer) > MaxDigitsForOctalInt + 2) { + if (!buffer || (size = strlen(buffer)) > MaxDigitsForOctalInt + 2) { if (ok) *ok = false; return 0; @@ -3548,7 +3550,7 @@ int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept #endif bool ok_ = true; const char *endptr; - const qlonglong value = qstrtoll(buffer, &endptr, 0, &ok_); + const qlonglong value = qstrntoll(buffer, size, &endptr, 0, &ok_); // Keep the following checks in sync with QByteArray::toInt() if (!ok_) { |