Add check for buffer empty/full in HAL_RingBuffer
@@ -1171,6 +1171,13 @@ public:
// Push a single element to the buffer.
size_t Push(const T data)
{
+ // check for buffer full
+ if(_size == _capacity)
+ {
+ // buffer full
+ return 0;
+ }
+
T* destination = _buffer;
destination += _write_index;
@@ -1194,6 +1201,13 @@ public:
// sanity check for 0 length
if (length == 0) return 0;
+ // check for buffer full
+ if(_size == _capacity)
+ {
+ // buffer full
+ return 0;
+ }
+
if( (length * _dataSize) < (_capacity - _size))
{
lengthToWrite = (length * _dataSize);
@@ -1238,6 +1252,12 @@ public:
// sanity check for 0 length
if (length == 0) return 0;
+ // check for buffer empty
+ if(_size == 0)
+ {
+ return 0;
+ }
+
lengthToRead = (length * _dataSize);
// can read in a single memcpy
@@ -1284,6 +1304,12 @@ public:
// sanity check for 0 length
if (length == 0) return 0;
+ // check for buffer empty
+ if(_size == 0)
+ {
+ return 0;
+ }
+
lengthToRead = (length * _dataSize);
// can read in a single memcpy
