Skip to content

Commit 9a14dd6

Browse files
committed
Fixing bugs when attempting to read from ringbuffer
1 parent b7edc11 commit 9a14dd6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: api/RingBuffer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class RingBufferN
5353

5454
private:
5555
int nextIndex(int index);
56+
inline bool isEmpty() const { return (_numElems == 0); }
5657
};
5758

5859
typedef RingBufferN<SERIAL_BUFFER_SIZE> RingBuffer;
@@ -91,7 +92,7 @@ void RingBufferN<N>::clear()
9192
template <int N>
9293
int RingBufferN<N>::read_char()
9394
{
94-
if(_iTail == _iHead)
95+
if (isEmpty())
9596
return -1;
9697

9798
uint8_t value = _aucBuffer[_iTail];
@@ -116,7 +117,7 @@ int RingBufferN<N>::availableForStore()
116117
template <int N>
117118
int RingBufferN<N>::peek()
118119
{
119-
if(_iTail == _iHead)
120+
if (isEmpty())
120121
return -1;
121122

122123
return _aucBuffer[_iTail];

0 commit comments

Comments
 (0)