summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2014-12-08 10:59:23 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2015-01-09 21:40:37 +0100
commit076148c7dd9de01eb1224e20223d44f5c357ed6b (patch)
tree58afb28700839d2a1f44d0f5acb365bc0dedd8da
parentf496c7186ca358f549e3aa32ac862a6f66011db6 (diff)
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 <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qringbuffer_p.h2
1 files changed, 1 insertions, 1 deletions
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