summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-11-20 12:50:41 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-11-20 15:33:00 (GMT)
commitb7692016f282251002b3e85dfcb5567bd91a12c0 (patch)
treeac3ba927000938e56508c06ddcce6e5f06430357 /src/corelib/io/qiodevice.cpp
parentbda75bfc7cf0137474005a0a733ff83e2aae16e9 (diff)
downloadQt-b7692016f282251002b3e85dfcb5567bd91a12c0.zip
Qt-b7692016f282251002b3e85dfcb5567bd91a12c0.tar.gz
Qt-b7692016f282251002b3e85dfcb5567bd91a12c0.tar.bz2
Fix regression introduced in 1e6b424b692b20dcfec920f8d3563e520ec1ff05
When processing the result of QIODevice::readLine, forgot to take into account that a '\0' is appended to the array. The terminating character is not accounted for in the number of bytes returned. By pre-allocating a byte for the terminating null character, we make sure we'll actually read 16k bytes on each and every iteration. Task-number: QTBUG-6019 Reviewed-by: Thiago Macieira
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r--src/corelib/io/qiodevice.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index b84961f..0e5a2de 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -1157,6 +1157,10 @@ QByteArray QIODevice::readLine(qint64 maxSize)
// If resize fails or maxSize == 0, read incrementally
if (maxSize == 0)
maxSize = INT_MAX;
+
+ // The first iteration needs to leave an extra byte for the terminating null
+ result.resize(1);
+
qint64 readResult;
do {
result.resize(int(qMin(maxSize, result.size() + QIODEVICE_BUFFERSIZE)));
@@ -1164,7 +1168,7 @@ QByteArray QIODevice::readLine(qint64 maxSize)
if (readResult > 0 || readBytes == 0)
readBytes += readResult;
} while (readResult == QIODEVICE_BUFFERSIZE
- && result[int(readBytes)] != '\n');
+ && result[int(readBytes - 1)] != '\n');
} else
readBytes = readLine(result.data(), result.size());