diff options
author | Øystein Heskestad <oystein.heskestad@qt.io> | 2022-01-05 13:10:17 +0100 |
---|---|---|
committer | Øystein Heskestad <oystein.heskestad@qt.io> | 2022-01-07 14:31:38 +0100 |
commit | 18671b0491e4806fdff95aac6c16a067890ef030 (patch) | |
tree | 41fad02e0756f430993aadf377189c14b5f62889 /src/corelib/io | |
parent | a5b158ed6dd5e393eab78f4034a93ac1250850e3 (diff) |
Replace QString::utf16() with data() in memcpy() and QByteArray ctor
QString::utf16() needlessly detaches fromRawData() to ensure a
terminating NUL. Use data() where we don't require said NUL, taking
care not to call the mutable data() overload, which would detach,
too.
Task-number: QTBUG-98763
Change-Id: I7075a8f18ab1f82ebbcf8cfab1643e8ab7f38d51
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qsettings_win.cpp | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index d316af7c38..aaaccf4e0d 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -471,14 +471,14 @@ static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Map &e envlist.resize(envlist.size() + tmpSize); tmpSize = it.key().length() * sizeof(wchar_t); - memcpy(envlist.data() + pos, it.key().utf16(), tmpSize); + memcpy(envlist.data() + pos, it.key().data(), tmpSize); pos += tmpSize; memcpy(envlist.data() + pos, &equal, sizeof(wchar_t)); pos += sizeof(wchar_t); tmpSize = it.value().length() * sizeof(wchar_t); - memcpy(envlist.data() + pos, it.value().utf16(), tmpSize); + memcpy(envlist.data() + pos, it.value().data(), tmpSize); pos += tmpSize; memcpy(envlist.data() + pos, &nul, sizeof(wchar_t)); diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 00a333098d..5146009c71 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -672,8 +672,8 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) } if (type == REG_BINARY) { - QString s = variantToString(value); - regValueBuff = QByteArray(reinterpret_cast<const char*>(s.utf16()), s.length() * 2); + const QString s = variantToString(value); + regValueBuff = QByteArray(reinterpret_cast<const char *>(s.data()), s.length() * 2); } else { QStringList::const_iterator it = l.constBegin(); for (; it != l.constEnd(); ++it) { |