diff --git a/components/freertos/ringbuf.c b/components/freertos/ringbuf.c index e49b8e5ef..ec4322df8 100644 --- a/components/freertos/ringbuf.c +++ b/components/freertos/ringbuf.c @@ -337,7 +337,7 @@ static void returnItemToRingbufDefault(ringbuf_t *rb, void *item) { uint8_t *data=(uint8_t*)item; configASSERT(((int)rb->free_ptr&3)==0); configASSERT(data >= rb->data); - configASSERT(data < rb->data+rb->size); + configASSERT(data <= rb->data+rb->size); //Grab the buffer entry that preceeds the buffer buf_entry_hdr_t *hdr=(buf_entry_hdr_t*)(data-sizeof(buf_entry_hdr_t)); configASSERT(hdr->len < rb->size); diff --git a/components/freertos/test/test_ringbuf.c b/components/freertos/test/test_ringbuf.c index bb8fc7253..ac2e88fe5 100644 --- a/components/freertos/test/test_ringbuf.c +++ b/components/freertos/test/test_ringbuf.c @@ -195,3 +195,26 @@ TEST_CASE("FreeRTOS ringbuffer test, w/ splitting items", "[freertos][ignore]") testRingbuffer(1); } + +TEST_CASE("FreeRTOS ringbuffer test, check if zero-length items are handled correctly", "[freertos]") +{ + rb = xRingbufferCreate(32, 0); + int r; + void *v; + size_t sz; + for (int x=0; x<128; x++) { + if (x!=127) { + //Send an item + r = xRingbufferSend(rb, NULL, 0, 10000 / portTICK_PERIOD_MS); + assert(r==pdTRUE); + } + if (x!=0) { + //Receive an item + v=xRingbufferReceive(rb, &sz, 10000 / portTICK_PERIOD_MS); + assert(sz==0); + vRingbufferReturnItem(rb, v); //actually not needed for NULL data... + } + } + vRingbufferDelete(rb); +} +