FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.71k stars 1.11k forks source link

[BUG] Violation of MISRA 2012 Rule 5.5: Identifiers shall be distinct from macro names #1058

Closed markhermeling closed 4 months ago

markhermeling commented 4 months ago

Describe the bug in include/semphr.h, line 675:

define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) )

In the same file, line 26:

ifdef xSemaphoreTakeFromISR

hard_undef xSemaphoreTakeFromISR

BaseType_t xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, BaseType_t * const pxHigherPriorityTaskWoken )

The macro and the function have the same name, which is a violation of rule 5.5

The same happens to xSemaphoreGive at line 460 and 23

Target

Host

To Reproduce Run codesonar analyze -preset misra2012 on the Coverity example

Expected behavior Either add a deviation, or change the code to have none distinct names for the macro and the function

Screenshots SARIF file attached

MISRA-violation-5.5.sarif.zip

RichardBarry commented 4 months ago

Hi, thanks for this. I would be grateful if you can post links to the referenced lines as line 26 in semphr.h appears to be a comment.

kar-rahul-aws commented 4 months ago

Hi @markhermeling Thanks for reporting the issue. We only see the function prototypes in the comments as pointed out by @RichardBarry . This would likely not cause an issue, since the macro definitions are proper in the source include file. Could you please provide more information on the lines( which are not comments ) which have similar issue.

Thanks.

markhermeling commented 4 months ago

Ah, I see what is going on. Let me retract this bug. This configuration of FreeRTOS used a #define for xSemaphoreTakeFromISR, where the CodeSonar model for FreeRTOS is expecting a function and the two are clashing.

This is not a problem in FreeRTOS, sorry for the noice