From 076148c7dd9de01eb1224e20223d44f5c357ed6b Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Mon, 8 Dec 2014 10:59:23 +0200 Subject: QRingBuffer: retrieve pointer to data more carefully An empty ring buffer always has a pre-cached byte array in its container. In this case size() indicates that no data is available, but readPointer() tries to resolve this byte array. To avoid an illegal pointer as a result, return Q_NULLPTR instead. Change-Id: Icc5f08f071a8f02a14c112b6e1adbe5373bd9466 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/tools/qringbuffer_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 58227d6755..610c099733 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -63,7 +63,7 @@ public: } inline const char *readPointer() const { - return buffers.isEmpty() ? 0 : (buffers.first().constData() + head); + return bufferSize == 0 ? Q_NULLPTR : (buffers.first().constData() + head); } // access the bytes at a specified position -- cgit v1.2.3