Ex44. RingBuffer_available_data problem

I’ve get stuck with the exercise 44 where the ring buffer is implemented.

Pre-Condition:
Get a RingBuffer with lnegth = 100 (for example)

Step to reproduse:

  1. Put 100 elements to the RingBuffer. So it should be full now.
  2. Get 2 elements from it.
  3. Do the RingBuffer_commit_read(buffer, 2). So start=2 now.
  4. Check RingBuffer_available_data(buffer)

Expected result:
RingBuffer_available_data return 98

Actual result:
RingBuffer_available_data return -3

IMHO
((B)->end + 1) % (B)->length - (B)->start - 1
will not work if RB is full, because when ((B)->end + 1) == (B)->length, then ((B)->end + 1) % (B)->length = 0 and result is always - (B)->start - 1, but there is still some data in the RB.
Is that a bug in the algorithm or just a wrong usage of the RingBuffer?

Thanks!
Mike

This should be fixed in the github repo: