summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-11-27 13:28:45 +0100
committerLars Knoll <lars.knoll@theqtcompany.com>2016-03-08 08:59:19 +0000
commitd0b54cede8d8ea0b8431c64abb51d0cd1a71327b (patch)
tree19920140690359aedc71133153d7580f1c8fb4ee /src/corelib
parentf2bd0d119200d5b66069725563f7f12952e66da8 (diff)
Ensure QTextStream doesn't modify the Text flag on the underlying iodevice
An empty read or a failed write on the underlying QIODevice of the text stream would lead to an early return where we wouldn't correctly restore the QIODevice::Text flag of the io device. Change-Id: I5b632f45dea6ede3f408113556c3dad1b96574e2 Task-number: QTBUG-47176 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qtextstream.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp
index a8fd2dd7ab..78dcbfe0e7 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -449,6 +449,10 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
bytesRead = device->read(buf, sizeof(buf));
}
+ // reset the Text flag.
+ if (textModeEnabled)
+ device->setTextModeEnabled(true);
+
if (bytesRead <= 0)
return false;
@@ -484,10 +488,6 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
readBuffer += QString::fromLatin1(buf, bytesRead);
#endif
- // reset the Text flag.
- if (textModeEnabled)
- device->setTextModeEnabled(true);
-
// remove all '\r\n' in the string.
if (readBuffer.size() > oldReadBufferSize && textModeEnabled) {
QChar CR = QLatin1Char('\r');
@@ -586,17 +586,18 @@ void QTextStreamPrivate::flushWriteBuffer()
qDebug("QTextStreamPrivate::flushWriteBuffer(), device->write(\"%s\") == %d",
qt_prettyDebug(data.constData(), qMin(data.size(),32), data.size()).constData(), int(bytesWritten));
#endif
- if (bytesWritten <= 0) {
- status = QTextStream::WriteFailed;
- return;
- }
#if defined (Q_OS_WIN)
- // replace the text flag
+ // reset the text flag
if (textModeEnabled)
device->setTextModeEnabled(true);
#endif
+ if (bytesWritten <= 0) {
+ status = QTextStream::WriteFailed;
+ return;
+ }
+
// flush the file
#ifndef QT_NO_QOBJECT
QFileDevice *file = qobject_cast<QFileDevice *>(device);