3 FreeRTOS-Kernel conforms to [MISRA C:2012](https://www.misra.org.uk/misra-c)
4 guidelines, with the deviations listed below. Compliance is checked with
5 Coverity static analysis version 2023.6.1. Since the FreeRTOS kernel is
6 designed for small-embedded devices, it needs to have a very small memory
7 footprint and has to be efficient. To achieve that and to increase the
8 performance, it deviates from some MISRA rules. The specific deviations,
9 suppressed inline, are listed below.
11 Additionally, [MISRA configuration file](examples/coverity/coverity_misra.config)
12 contains project wide deviations.
14 ### Suppressed with Coverity Comments
15 To find the violation references in the source files run grep on the source code
16 with ( Assuming rule 8.4 violation; with justification in point 1 ):
18 grep 'MISRA Ref 8.4.1' . -rI
22 MISRA C:2012 Dir 4.7: If a function returns error information, then that error
23 information shall be tested.
26 - `taskENTER_CRITICAL_FROM_ISR` returns the interrupt mask and not any error
27 information. Therefore, there is no need test the return value.
31 MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
32 object or function with external linkage is defined.
35 - pxCurrentTCB(s) is defined with external linkage but it is only referenced
36 from the assembly code in the port files. Therefore, adding a declaration in
37 header file is not useful as the assembly code will still need to declare it
41 - xQueueRegistry is defined with external linkage because it is accessed by the
42 kernel unit tests. It is not meant to be directly accessed by the application
43 and therefore, not declared in a header file.
47 MISRA C:2012 Rule 8.6: An identifier with external linkage shall have exactly
48 one external definition.
51 - This rule prohibits an identifier with external linkage to have multiple
52 definitions or no definition. FreeRTOS hook functions are implemented in
53 the application and therefore, have no definition in the Kernel code.
56 MISRA C:2012 Rule 11.1: Conversions shall not be performed between a pointer to
57 function and any other type.
60 - The pointer to function is casted into void to avoid unused parameter
61 compiler warning when Stream Buffer's Tx and Rx Completed callback feature is
66 MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to
67 object type and a pointer to a different object type.
70 - This rule prohibits casting a pointer to object into a pointer to a
71 different object because it may result in an incorrectly aligned pointer,
72 leading to undefined behavior. Even if the casting produces a correctly
73 aligned pointer, the behavior may be still undefined if the pointer is
74 used to access an object. FreeRTOS deliberately creates external aliases
75 for all the kernel object types (StaticEventGroup_t, StaticQueue_t,
76 StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding
77 purposes. The internal object types and the corresponding external
78 aliases are guaranteed to have the same size and alignment which is
79 checked using configASSERT.
84 MISRA C:2012 Rule 11.5: A conversion should not be performed from pointer to
85 void into pointer to object.
86 This rule prohibits conversion of a pointer to void into a pointer to
87 object because it may result in an incorrectly aligned pointer leading
88 to undefined behavior.
91 - The memory blocks returned by pvPortMalloc() are guaranteed to meet the
92 architecture alignment requirements specified by portBYTE_ALIGNMENT.
93 The casting of the pointer to void returned by pvPortMalloc() is,
94 therefore, safe because it is guaranteed to be aligned.
97 - The conversion from a pointer to void into a pointer to EventGroup_t is
98 safe because it is a pointer to EventGroup_t, which is returned to the
99 application at the time of event group creation for data hiding
103 - The conversion from a pointer to void in list macros for list item owner
104 is safe because the type of the pointer stored and retrieved is the
108 - The conversion from a pointer to void into a pointer to EventGroup_t is
109 safe because it is a pointer to EventGroup_t, which is passed as a
110 parameter to the xTimerPendFunctionCallFromISR API when the callback is
114 - The conversion from a pointer to void into a pointer to uint8_t is safe
115 because data storage buffers are implemented as uint8_t arrays for the
116 ease of sizing, alignment and access.
120 MISRA C-2012 Rule 14.3: Controlling expressions shall not be invariant.
123 - The `configMAX_TASK_NAME_LEN` , `taskRESERVED_TASK_NAME_LENGTH` and `SIZE_MAX`
124 are evaluated to constants at compile time and may vary based on the build
129 MISRA C-2012 Rule 18.1: A pointer resulting from arithmetic on a pointer operand
130 shall address an element of the same array as that pointer operand.
133 - Array access remains within bounds since either the null terminator in
134 the IDLE task name will break the loop, or the loop will break normally
135 if the array size is smaller than the IDLE task name length.
139 MISRA C-2012 Rule 21.6: The Standard Library input/output functions shall not
143 - The Standard Library function snprintf is used in vTaskListTasks and
144 vTaskGetRunTimeStatistics APIs, both of which are utility functions only and
145 are not considered part of core kernel implementation.