diff options
author | João Abecasis <joao@abecasis.name> | 2009-11-20 12:50:41 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-11-23 12:13:17 (GMT) |
commit | 6adeb8be007bfdeaeb7e1d4a730abf32dbdb0f7d (patch) | |
tree | 2398fdf65014314156c4850ce22fecc0535f89c0 /src | |
parent | d180aa547065698cf18d25c65730689ae456c802 (diff) | |
download | Qt-6adeb8be007bfdeaeb7e1d4a730abf32dbdb0f7d.zip Qt-6adeb8be007bfdeaeb7e1d4a730abf32dbdb0f7d.tar.gz Qt-6adeb8be007bfdeaeb7e1d4a730abf32dbdb0f7d.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
(cherry picked from commit b7692016f282251002b3e85dfcb5567bd91a12c0)
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 0248224..3b569b7 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1164,6 +1164,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))); @@ -1171,7 +1175,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()); |