From 8c2503c289a60a049d8d0055b51bda9280383453 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Tue, 28 Nov 2023 12:14:08 +0000 Subject: [PATCH] Code review suggestions Signed-off-by: Gaurav Aggarwal --- MISRA.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/MISRA.md b/MISRA.md index e2316d85411..90df7b3e00d 100644 --- a/MISRA.md +++ b/MISRA.md @@ -36,16 +36,18 @@ _Ref 8.4.1_ _Ref 11.3.1_ -- MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to object - type and a pointer to a different object type. - The rule requires not to cast a pointer to object into a pointer to a - different object to prevent undefined behavior due to incorrectly aligned. - To support static memory allocation, FreeRTOS creates static type kernel - objects which are aliases for kernel object type with prefix "Static" for - data hiding purpose. A static kernel object type is guaranteed to have the - same size and alignment with kernel object, which is checked by configASSERT. - Static kernel object types include StaticEventGroup_t, StaticQueue_t, - StaticStreamBuffer_t, StaticTimer_t and StaticTask_t. +- MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to + object type and a pointer to a different object type. + This rule prohibits casting a pointer to object into a pointer to a + different object because it may result in an incorrectly aligned pointer, + leading to undefined behavior. Even if the casting produces a correctly + aligned pointer, the behavior may be still undefined if the pointer is + used to access an object. FreeRTOS deliberately creates external aliases + for all the kernel object types (StaticEventGroup_t, StaticQueue_t, + StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding + purposes. The internal object types and the corresponding external + aliases are guarnteed to have the same size and alignment which is + checked using configASSERT. ### MISRA configuration