summaryrefslogtreecommitdiffstats
path: root/tests/auto/qbuffer/tst_qbuffer.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2010-05-06 17:07:39 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2010-05-07 08:36:01 (GMT)
commitf380ab3106cb6d39087adacd77f618184f6f90c3 (patch)
treeab917cf7bbc2304a33750f10d719c8395e1a116f /tests/auto/qbuffer/tst_qbuffer.cpp
parent19db30f5b0a8a9a068a9acf9a20f08c86165393e (diff)
downloadQt-f380ab3106cb6d39087adacd77f618184f6f90c3.zip
Qt-f380ab3106cb6d39087adacd77f618184f6f90c3.tar.gz
Qt-f380ab3106cb6d39087adacd77f618184f6f90c3.tar.bz2
Fixed bug in QIODevice::read after first reading 0 bytes.
Change 02532ec80375c686503c4250c6ad6bb211515ec8 removed the early-exit for 0 byte reads, causing us to hit code that assumed the buffer was empty since nothing was read. It would thus read more into the end of the buffer, causing the buffer to grow bigger than QIODEVICE_BUFFERSIZE. Next, if the actual number of bytes we wanted to read was bigger than the original buffer size we'd read the same data twice. Reviewed-by: João Abecasis Reviewed-by: Thiago Macieira
Diffstat (limited to 'tests/auto/qbuffer/tst_qbuffer.cpp')
-rw-r--r--tests/auto/qbuffer/tst_qbuffer.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qbuffer/tst_qbuffer.cpp b/tests/auto/qbuffer/tst_qbuffer.cpp
index fcef6a3..dd5ca91 100644
--- a/tests/auto/qbuffer/tst_qbuffer.cpp
+++ b/tests/auto/qbuffer/tst_qbuffer.cpp
@@ -76,6 +76,7 @@ private slots:
void atEnd();
void readLineBoundaries();
void writeAfterQByteArrayResize();
+ void read_null();
protected slots:
void readyReadSlot();
@@ -529,5 +530,30 @@ void tst_QBuffer::writeAfterQByteArrayResize()
QCOMPARE(buffer.buffer().size(), 1000);
}
+void tst_QBuffer::read_null()
+{
+ QByteArray buffer;
+ buffer.resize(32000);
+ for (int i = 0; i < buffer.size(); ++i)
+ buffer[i] = char(i & 0xff);
+
+ QBuffer in(&buffer);
+ in.open(QIODevice::ReadOnly);
+
+ QByteArray chunk;
+
+ chunk.resize(16380);
+ in.read(chunk.data(), 16380);
+
+ QCOMPARE(chunk, buffer.mid(0, chunk.size()));
+
+ in.read(chunk.data(), 0);
+
+ chunk.resize(8);
+ in.read(chunk.data(), chunk.size());
+
+ QCOMPARE(chunk, buffer.mid(16380, chunk.size()));
+}
+
QTEST_MAIN(tst_QBuffer)
#include "tst_qbuffer.moc"