From 964d76797657b64206f8bbd54eeb69ce27d66b56 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Thu, 2 Jul 2015 09:42:08 +0300 Subject: [PATCH] QRingBuffer::reserveFront(): do not leave empty array in buffer list Fix the corner case when called on empty buffer. Change-Id: I1316de7fbe69f3db40a7fdde06336e53d82675c9 Reviewed-by: Oswald Buddenhagen --- src/corelib/tools/qringbuffer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index 658267a521..85cfdaf129 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -138,10 +138,14 @@ char *QRingBuffer::reserveFront(qint64 bytes) if (tailBuffer == 0) tail -= head; - buffers.prepend(QByteArray()); head = qMax(basicBlockSize, int(bytes)); + if (bufferSize == 0) { + tail = head; + } else { + buffers.prepend(QByteArray()); + ++tailBuffer; + } buffers.first().resize(head); - ++tailBuffer; } head -= int(bytes);