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 Pick-to: 6.4 6.3 6.2 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>bb10
parent
15368fb31b
commit
c25cc34a05
|
|
@ -48,7 +48,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'));
|
||||
|
|
@ -109,15 +109,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…
Reference in New Issue