From 2a04297e64c559b79724e1576c7d8b4e2723a3c0 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 19 Nov 2024 11:07:51 +0800 Subject: [PATCH] fix(ringbuf): fixed logic errors when compiling with CONFIG_COMPILER_STATIC_ANALYZER ESP_STATIC_ANALYZER_CHECK was added to remove some static analyzer warning about null pointer dereferences that should never happen, but the logic was wrong. We return pdFALSE if prvReceiveGeneric was called with any of the input pointers as NULL, but pvItem2 and xItemSize2 will only be non-null for split buffers. Closes https://github.com/espressif/esp-idf/issues/14905 --- components/esp_ringbuf/ringbuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/esp_ringbuf/ringbuf.c b/components/esp_ringbuf/ringbuf.c index 3892c90253e..41109ee3094 100644 --- a/components/esp_ringbuf/ringbuf.c +++ b/components/esp_ringbuf/ringbuf.c @@ -829,7 +829,7 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer, BaseType_t xEntryTimeSet = pdFALSE; TimeOut_t xTimeOut; - ESP_STATIC_ANALYZER_CHECK(!pvItem1 || !pvItem2 || !xItemSize1 || !xItemSize2, pdFALSE); + ESP_STATIC_ANALYZER_CHECK(!pvItem1 || !xItemSize1, pdFALSE); while (xExitLoop == pdFALSE) { portENTER_CRITICAL(&pxRingbuffer->mux); @@ -845,6 +845,7 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer, } //If split buffer, check for split items if (pxRingbuffer->uxRingbufferFlags & rbALLOW_SPLIT_FLAG) { + ESP_STATIC_ANALYZER_CHECK(!pvItem2 || !xItemSize2, pdFALSE); if (xIsSplit == pdTRUE) { *pvItem2 = pxRingbuffer->pvGetItem(pxRingbuffer, &xIsSplit, 0, xItemSize2); configASSERT(*pvItem2 < *pvItem1); //Check wrap around has occurred @@ -890,7 +891,7 @@ static BaseType_t prvReceiveGenericFromISR(Ringbuffer_t *pxRingbuffer, { BaseType_t xReturn = pdFALSE; - ESP_STATIC_ANALYZER_CHECK(!pvItem1 || !pvItem2 || !xItemSize1 || !xItemSize2, pdFALSE); + ESP_STATIC_ANALYZER_CHECK(!pvItem1 || !xItemSize1, pdFALSE); portENTER_CRITICAL_ISR(&pxRingbuffer->mux); if (prvCheckItemAvail(pxRingbuffer) == pdTRUE) { @@ -904,6 +905,7 @@ static BaseType_t prvReceiveGenericFromISR(Ringbuffer_t *pxRingbuffer, } //If split buffer, check for split items if (pxRingbuffer->uxRingbufferFlags & rbALLOW_SPLIT_FLAG) { + ESP_STATIC_ANALYZER_CHECK(!pvItem2 || !xItemSize2, pdFALSE); if (xIsSplit == pdTRUE) { *pvItem2 = pxRingbuffer->pvGetItem(pxRingbuffer, &xIsSplit, 0, xItemSize2); configASSERT(*pvItem2 < *pvItem1); //Check wrap around has occurred