Fix a crash in QClipBoard when copying utf16 data
Properly use the new QStringConverter API and not an internal qFromUtfEncoded method that was buggy after the changes. Take the oppportunity to clean up and remove qFromUtfEncoded, as QClipboard was its only user. Fixes: QTBUG-85417 Change-Id: I8540d12056bf3f448c1f628ce0bd0ad462a6447d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
cd67fe5821
commit
a5025efccf
@ -1067,26 +1067,6 @@ QChar *QUtf32::convertToUnicode(QChar *out, const char *chars, qsizetype len, QS
|
||||
return out;
|
||||
}
|
||||
|
||||
QString qFromUtfEncoded(const QByteArray &ba)
|
||||
{
|
||||
const qsizetype arraySize = ba.size();
|
||||
const uchar *buf = reinterpret_cast<const uchar *>(ba.constData());
|
||||
const uint bom = 0xfeff;
|
||||
|
||||
if (arraySize > 3) {
|
||||
uint uc = qFromUnaligned<uint>(buf);
|
||||
if (uc == qToBigEndian(bom) || uc == qToLittleEndian(bom))
|
||||
return QUtf32::convertToUnicode(ba.constData(), ba.length(), nullptr); // utf-32
|
||||
}
|
||||
|
||||
if (arraySize > 1) {
|
||||
ushort uc = qFromUnaligned<ushort>(buf);
|
||||
if (uc == qToBigEndian(ushort(bom)) || qToLittleEndian(ushort(bom)))
|
||||
return QUtf16::convertToUnicode(ba.constData(), ba.length(), nullptr); // utf-16
|
||||
}
|
||||
return QUtf8::convertToUnicode(ba.constData(), ba.length());
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)
|
||||
static QString convertToUnicodeCharByChar(const char *chars, qsizetype length, QStringConverter::State *state)
|
||||
{
|
||||
|
@ -331,12 +331,6 @@ struct Q_CORE_EXPORT QLocal8Bit
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
Converts from different utf encodings looking at a possible byte order mark at the
|
||||
beginning of the string. If no BOM exists, utf-8 is assumed.
|
||||
*/
|
||||
Q_CORE_EXPORT QString qFromUtfEncoded(const QByteArray &ba);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QSTRINGCONVERTER_P_H
|
||||
|
@ -286,7 +286,10 @@ QString QClipboard::text(QString &subtype, Mode mode) const
|
||||
}
|
||||
|
||||
const QByteArray rawData = data->data(QLatin1String("text/") + subtype);
|
||||
return qFromUtfEncoded(rawData);
|
||||
auto encoding = QStringConverter::encodingForData(rawData.constData(), rawData.size());
|
||||
if (!encoding)
|
||||
encoding = QStringConverter::Utf8;
|
||||
return QStringDecoder(*encoding).decode(rawData);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
x
Reference in New Issue
Block a user