Port qenvironmentvariables.cpp to qsizetype
I don't expect environments to allow values or names > 2 Gi characters, so this is just for consistency (int is a code smell these days). As a drive-by, replace QString buffer; buffer.resize(n); with QString buffer(n, Qt::Uninitialized); Task-number: QTBUG-103527 Change-Id: I0e41a6e7e9c44ff1ec22377329735538d5f95181 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit c25cc34a05c0838052b9a5d6624336ef2a2ae8ea) Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
b491bf11d6
commit
30e9cf6be0
@ -3405,7 +3405,7 @@ QByteArray qgetenv(const char *varName)
|
||||
getenv_s(&requiredSize, 0, 0, varName);
|
||||
if (requiredSize == 0)
|
||||
return buffer;
|
||||
buffer.resize(int(requiredSize));
|
||||
buffer.resize(qsizetype(requiredSize));
|
||||
getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
|
||||
// requiredSize includes the terminating null, which we don't want.
|
||||
Q_ASSERT(buffer.endsWith('\0'));
|
||||
@ -3466,15 +3466,14 @@ QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
const auto locker = qt_scoped_lock(environmentMutex);
|
||||
QVarLengthArray<wchar_t, 32> wname(int(strlen(varName)) + 1);
|
||||
for (int i = 0; i < wname.size(); ++i) // wname.size() is correct: will copy terminating null
|
||||
QVarLengthArray<wchar_t, 32> wname(qsizetype(strlen(varName)) + 1);
|
||||
for (qsizetype i = 0; i < wname.size(); ++i) // wname.size() is correct: will copy terminating null
|
||||
wname[i] = uchar(varName[i]);
|
||||
size_t requiredSize = 0;
|
||||
QString buffer;
|
||||
_wgetenv_s(&requiredSize, 0, 0, wname.data());
|
||||
if (requiredSize == 0)
|
||||
return defaultValue;
|
||||
buffer.resize(int(requiredSize));
|
||||
QString buffer(qsizetype(requiredSize), Qt::Uninitialized);
|
||||
_wgetenv_s(&requiredSize, reinterpret_cast<wchar_t *>(buffer.data()), requiredSize,
|
||||
wname.data());
|
||||
// requiredSize includes the terminating null, which we don't want.
|
||||
|
Loading…
x
Reference in New Issue
Block a user