Explorar o código

Fix an assert that erroneously triggered when popping a zero-byte payload from the end of the ringbuffer

Jeroen Domburg %!s(int64=8) %!d(string=hai) anos
pai
achega
d0bf9e61da
Modificáronse 2 ficheiros con 24 adicións e 1 borrados
  1. 1 1
      components/freertos/ringbuf.c
  2. 23 0
      components/freertos/test/test_ringbuf.c

+ 1 - 1
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);

+ 23 - 0
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);
+}
+