lpcware

LPCOpen 11Uxx V2.06 Ringbuffer bug

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by pat180269 on Tue Oct 27 03:12:31 MST 2015
There is a bug in ring_buffer.c

The macros used for adjusting the head and tail pointers are

#define RB_INDH(rb)                ((rb)->head & ((rb)->(count-1))
#define RB_INDT(rb)                ((rb)->tail    & ((rb)->(count-1))

but they should be

#define RB_INDH(rb)                ((rb)->head % ((rb)->count))
#define RB_INDT(rb)                ((rb)->tail    % ((rb)->count))

The code is very confusing because data is inserted at the head and popped from the tail which is counter intuitive.

Outcomes