diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2015-05-06 22:24:46 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-05-13 01:08:39 +0000 |
commit | 237e73df945ad9a82a658647a28706d04b63a6a6 (patch) | |
tree | 9cfec626b7ed44215e560a1d74278080fa7fb78c /src/corelib | |
parent | 43cab86802fb5a7447e6fd2d451f97a37b53f13c (diff) |
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, or due to the codec name/mib being
unsupported by ICU. If that's the case, QTextStream needs to fall back
to Latin 1, like QString::toLocal8Bit and fromLocal8Bit already do.
Change-Id: Ia888243669e051e78e0dbe0bb1bc55a1c4f519d8
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qtextstream.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 5fe4cfef9d..47b96d708f 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -464,7 +464,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) } #if defined (QTEXTSTREAM_DEBUG) qDebug("QTextStreamPrivate::fillReadBuffer(), using %s codec", - codec->name().constData()); + codec ? codec->name().constData() : "no"); #endif #endif @@ -476,9 +476,10 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) int oldReadBufferSize = readBuffer.size(); #ifndef QT_NO_TEXTCODEC // convert to unicode - readBuffer += codec->toUnicode(buf, bytesRead, &readConverterState); + readBuffer += Q_LIKELY(codec) ? codec->toUnicode(buf, bytesRead, &readConverterState) + : QString::fromLatin1(buf, bytesRead); #else - readBuffer += QString::fromLatin1(QByteArray(buf, bytesRead).constData()); + readBuffer += QString::fromLatin1(buf, bytesRead); #endif // reset the Text flag. @@ -564,7 +565,8 @@ void QTextStreamPrivate::flushWriteBuffer() codec = QTextCodec::codecForLocale(); #if defined (QTEXTSTREAM_DEBUG) qDebug("QTextStreamPrivate::flushWriteBuffer(), using %s codec (%s generating BOM)", - codec->name().constData(), writeConverterState.flags & QTextCodec::IgnoreHeader ? "not" : ""); + codec ? codec->name().constData() : "no", + !codec || (writeConverterState.flags & QTextCodec::IgnoreHeader) ? "not" : ""); #endif // convert from unicode to raw data @@ -572,7 +574,7 @@ void QTextStreamPrivate::flushWriteBuffer() QByteArray data = Q_LIKELY(codec) ? codec->fromUnicode(writeBuffer.data(), writeBuffer.size(), &writeConverterState) : writeBuffer.toLatin1(); #else - QByteArray data = writeBuffer.toLocal8Bit(); + QByteArray data = writeBuffer.toLatin1(); #endif writeBuffer.clear(); |