diff options
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index b17c6d2f40..5d25b0add1 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -90,7 +90,7 @@ public: // special case: it is in the first buffer int nextDataBlockSizeValue = nextDataBlockSize(); - if (pos - head < nextDataBlockSizeValue) { + if (pos < nextDataBlockSizeValue) { length = nextDataBlockSizeValue - pos; return buffers.at(0).constData() + head + pos; } diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp index 6780493206..285cc3042a 100644 --- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp +++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp @@ -111,6 +111,13 @@ void tst_QRingBuffer::readPointerAtPositionWithHead() buf2 = ringBuffer.readPointerAtPosition(0, length); QCOMPARE(length, qint64(0)); QVERIFY(buf2 == 0); + + // check buffer with 2 blocks + memcpy(ringBuffer.reserve(4), "0123", 4); + ringBuffer.append(QByteArray("45678", 5)); + ringBuffer.free(3); + buf2 = ringBuffer.readPointerAtPosition(1, length); + QCOMPARE(length, qint64(5)); } void tst_QRingBuffer::readPointerAtPositionEmptyRead() |