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>
This commit is contained in:
Alex Trotsenko 2014-12-08 10:59:23 +02:00
parent f496c7186c
commit 076148c7dd

View File

@ -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