Skip to content

Commit

Permalink
fix(ringbuf): fixed logic errors when compiling with CONFIG_COMPILER_…
Browse files Browse the repository at this point in the history
…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 #14905
  • Loading branch information
ESP-Marius committed Nov 29, 2024
1 parent da9e87a commit 2a04297
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/esp_ringbuf/ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 2a04297

Please sign in to comment.