Don't assume QLocale::codecForLocale always returns non-null
It may return null during program exit, due to QCoreGlobalData global static already having been destroyed. If that's the case, QTextStream needs to fall back to Latin 1, like QString::toLocal8Bit and fromLocal8Bit already do. Task-number: QTBUG-38316 Change-Id: I5949c8dec15b60f4a13b5d9307ed6abfc799fe20 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>bb10
parent
ec81021664
commit
f2a40fa071
|
|
@ -569,7 +569,9 @@ void QTextStreamPrivate::flushWriteBuffer()
|
|||
#endif
|
||||
|
||||
// convert from unicode to raw data
|
||||
QByteArray data = codec->fromUnicode(writeBuffer.data(), writeBuffer.size(), &writeConverterState);
|
||||
// codec might be null if we're already inside global destructors (QTestCodec::codecForLocale returned null)
|
||||
QByteArray data = Q_LIKELY(codec) ? codec->fromUnicode(writeBuffer.data(), writeBuffer.size(), &writeConverterState)
|
||||
: writeBuffer.toLatin1();
|
||||
#else
|
||||
QByteArray data = writeBuffer.toLocal8Bit();
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -247,6 +247,13 @@ private:
|
|||
QString testFileName;
|
||||
};
|
||||
|
||||
void runOnExit()
|
||||
{
|
||||
QByteArray buffer;
|
||||
QTextStream(&buffer) << "This will try to use QTextCodec::codecForLocale" << endl;
|
||||
}
|
||||
Q_DESTRUCTOR_FUNCTION(runOnExit)
|
||||
|
||||
tst_QTextStream::tst_QTextStream()
|
||||
: tempDir(QDir::tempPath() + "/tst_qtextstream.XXXXXX")
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue