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>
This commit is contained in:
parent
a5b158ed6d
commit
18671b0491
@ -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));
|
||||
|
@ -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) {
|
||||
|
@ -480,7 +480,7 @@ static QChar *createFontFile(const QString &faceName)
|
||||
if (!faceName.isEmpty()) {
|
||||
const int nameLength = qMin(faceName.length(), LF_FACESIZE - 1);
|
||||
faceNamePtr = new QChar[nameLength + 1];
|
||||
memcpy(static_cast<void *>(faceNamePtr), faceName.utf16(), sizeof(wchar_t) * nameLength);
|
||||
memcpy(static_cast<void *>(faceNamePtr), faceName.data(), sizeof(wchar_t) * nameLength);
|
||||
faceNamePtr[nameLength] = u'\0';
|
||||
}
|
||||
return faceNamePtr;
|
||||
@ -990,7 +990,7 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData,
|
||||
HDC hdc = GetDC(0);
|
||||
LOGFONT lf;
|
||||
memset(&lf, 0, sizeof(LOGFONT));
|
||||
memcpy(lf.lfFaceName, familyName.utf16(), sizeof(wchar_t) * qMin(LF_FACESIZE - 1, familyName.size()));
|
||||
memcpy(lf.lfFaceName, familyName.data(), sizeof(wchar_t) * qMin(LF_FACESIZE - 1, familyName.size()));
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
const QFontValues &values = fontValues.at(j);
|
||||
lf.lfWeight = values.weight;
|
||||
@ -1164,7 +1164,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
|
||||
const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam);
|
||||
if (nameSubstitute != fam) {
|
||||
const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1);
|
||||
memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t));
|
||||
memcpy(lf.lfFaceName, nameSubstitute.data(), nameSubstituteLength * sizeof(wchar_t));
|
||||
lf.lfFaceName[nameSubstituteLength] = 0;
|
||||
}
|
||||
|
||||
|
@ -1039,7 +1039,7 @@ public:
|
||||
const QString nameSubstitute = QSettings(QLatin1String(keyC), QSettings::NativeFormat).value(familyName, familyName).toString();
|
||||
if (nameSubstitute != familyName) {
|
||||
const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1);
|
||||
memcpy(lf.lfFaceName, nameSubstitute.utf16(), size_t(nameSubstituteLength) * sizeof(wchar_t));
|
||||
memcpy(lf.lfFaceName, nameSubstitute.data(), size_t(nameSubstituteLength) * sizeof(wchar_t));
|
||||
lf.lfFaceName[nameSubstituteLength] = 0;
|
||||
}
|
||||
|
||||
|
@ -670,7 +670,7 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
|
||||
auto *f = reinterpret_cast<wchar_t *>(files);
|
||||
for (int i=0; i<fileNames.size(); i++) {
|
||||
const auto l = size_t(fileNames.at(i).length());
|
||||
memcpy(f, fileNames.at(i).utf16(), l * sizeof(ushort));
|
||||
memcpy(f, fileNames.at(i).data(), l * sizeof(ushort));
|
||||
f += l;
|
||||
*f++ = 0;
|
||||
}
|
||||
@ -682,8 +682,8 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
|
||||
const auto urls = mimeData->urls();
|
||||
QByteArray result;
|
||||
if (!urls.isEmpty()) {
|
||||
QString url = urls.at(0).toString();
|
||||
result = QByteArray(reinterpret_cast<const char *>(url.utf16()),
|
||||
const QString url = urls.at(0).toString();
|
||||
result = QByteArray(reinterpret_cast<const char *>(url.data()),
|
||||
url.length() * int(sizeof(ushort)));
|
||||
}
|
||||
result.append('\0');
|
||||
|
@ -113,7 +113,7 @@ bool QXcbMime::mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeDa
|
||||
if (atomName == QLatin1String("text/uri-list")
|
||||
&& connection->atomName(a) == "text/x-moz-url") {
|
||||
const QString mozUri = QLatin1String(data->split('\n').constFirst()) + QLatin1Char('\n');
|
||||
*data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()),
|
||||
*data = QByteArray(reinterpret_cast<const char *>(mozUri.data()),
|
||||
mozUri.length() * 2);
|
||||
} else if (atomName == QLatin1String("application/x-color"))
|
||||
*dataFormat = 16;
|
||||
|
@ -808,11 +808,11 @@ bool QDB2Result::exec()
|
||||
break; }
|
||||
case QMetaType::QString:
|
||||
{
|
||||
QString str(values.at(i).toString());
|
||||
const QString str(values.at(i).toString());
|
||||
if (*ind != SQL_NULL_DATA)
|
||||
*ind = str.length() * sizeof(QChar);
|
||||
if (bindValueType(i) & QSql::Out) {
|
||||
QByteArray ba((char*)str.utf16(), str.capacity() * sizeof(QChar));
|
||||
QByteArray ba((char *)str.data(), str.capacity() * sizeof(QChar));
|
||||
r = SQLBindParameter(d->hStmt,
|
||||
i + 1,
|
||||
qParamType[bindValueType(i) & 3],
|
||||
|
Loading…
x
Reference in New Issue
Block a user