Skip to content

Commit dabbc05

Browse files
authored
Suppress MISRA C rule 11.3 in MISRA.md (#857)
Suppress MISRA C rule 11.3 in MISRA.md
1 parent f2637ba commit dabbc05

File tree

6 files changed

+62
-7
lines changed

6 files changed

+62
-7
lines changed

MISRA.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ _Ref 8.4.1_
3131
a declaration in header file is not useful as the assembly code will
3232
still need to declare it separately.
3333

34+
35+
#### Rule 11.3
36+
37+
_Ref 11.3.1_
38+
39+
- MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to
40+
object type and a pointer to a different object type.
41+
This rule prohibits casting a pointer to object into a pointer to a
42+
different object because it may result in an incorrectly aligned pointer,
43+
leading to undefined behavior. Even if the casting produces a correctly
44+
aligned pointer, the behavior may be still undefined if the pointer is
45+
used to access an object. FreeRTOS deliberately creates external aliases
46+
for all the kernel object types (StaticEventGroup_t, StaticQueue_t,
47+
StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding
48+
purposes. The internal object types and the corresponding external
49+
aliases are guaranteed to have the same size and alignment which is
50+
checked using configASSERT.
51+
52+
3453
### MISRA configuration
3554

3655
Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
@@ -69,4 +88,4 @@ Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
6988
}
7089
]
7190
}
72-
```
91+
```

event_groups.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
9898
#endif /* configASSERT_DEFINED */
9999

100100
/* The user has provided a statically allocated event group - use it. */
101-
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
101+
/* MISRA Ref 11.3.1 [Misaligned access] */
102+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
103+
/* coverity[misra_c_2012_rule_11_3_violation] */
104+
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer;
102105

103106
if( pxEventBits != NULL )
104107
{
@@ -710,6 +713,9 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
710713
/* Check if the event group was statically allocated. */
711714
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
712715
{
716+
/* MISRA Ref 11.3.1 [Misaligned access] */
717+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
718+
/* coverity[misra_c_2012_rule_11_3_violation] */
713719
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
714720
xReturn = pdTRUE;
715721
}
@@ -721,6 +727,9 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
721727
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
722728
{
723729
/* Event group must have been statically allocated. */
730+
/* MISRA Ref 11.3.1 [Misaligned access] */
731+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
732+
/* coverity[misra_c_2012_rule_11_3_violation] */
724733
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
725734
xReturn = pdTRUE;
726735
}

queue.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
408408
/* The address of a statically allocated queue was passed in, use it.
409409
* The address of a statically allocated storage area was also passed in
410410
* but is already set. */
411-
pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
411+
/* MISRA Ref 11.3.1 [Misaligned access] */
412+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
413+
/* coverity[misra_c_2012_rule_11_3_violation] */
414+
pxNewQueue = ( Queue_t * ) pxStaticQueue;
412415

413416
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
414417
{
@@ -459,6 +462,9 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
459462
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
460463
}
461464

465+
/* MISRA Ref 11.3.1 [Misaligned access] */
466+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
467+
/* coverity[misra_c_2012_rule_11_3_violation] */
462468
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
463469
xReturn = pdTRUE;
464470
}

stream_buffer.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
406406
StreamBufferCallbackFunction_t pxSendCompletedCallback,
407407
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )
408408
{
409-
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */
409+
/* MISRA Ref 11.3.1 [Misaligned access] */
410+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
411+
/* coverity[misra_c_2012_rule_11_3_violation] */
412+
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer;
410413
StreamBufferHandle_t xReturn;
411414
uint8_t ucFlags;
412415

@@ -466,7 +469,10 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
466469

467470
traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer );
468471

469-
xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */
472+
/* MISRA Ref 11.3.1 [Misaligned access] */
473+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
474+
/* coverity[misra_c_2012_rule_11_3_violation] */
475+
xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer;
470476
}
471477
else
472478
{
@@ -498,6 +504,9 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
498504
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 )
499505
{
500506
*ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer;
507+
/* MISRA Ref 11.3.1 [Misaligned access] */
508+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
509+
/* coverity[misra_c_2012_rule_11_3_violation] */
501510
*ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer;
502511
xReturn = pdTRUE;
503512
}

tasks.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,10 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
12711271
{
12721272
/* The memory used for the task's TCB and stack are passed into this
12731273
* function - use them. */
1274-
pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
1274+
/* MISRA Ref 11.3.1 [Misaligned access] */
1275+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
1276+
/* coverity[misra_c_2012_rule_11_3_violation] */
1277+
pxNewTCB = ( TCB_t * ) pxTaskBuffer;
12751278
( void ) memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
12761279
pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;
12771280

@@ -4354,6 +4357,9 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
43544357
if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB )
43554358
{
43564359
*ppuxStackBuffer = pxTCB->pxStack;
4360+
/* MISRA Ref 11.3.1 [Misaligned access] */
4361+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
4362+
/* coverity[misra_c_2012_rule_11_3_violation] */
43574363
*ppxTaskBuffer = ( StaticTask_t * ) pxTCB;
43584364
xReturn = pdTRUE;
43594365
}

timers.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@
394394

395395
/* A pointer to a StaticTimer_t structure MUST be provided, use it. */
396396
configASSERT( pxTimerBuffer );
397-
pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 !e9087 StaticTimer_t is a pointer to a Timer_t, so guaranteed to be aligned and sized correctly (checked by an assert()), so this is safe. */
397+
/* MISRA Ref 11.3.1 [Misaligned access] */
398+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
399+
/* coverity[misra_c_2012_rule_11_3_violation] */
400+
pxNewTimer = ( Timer_t * ) pxTimerBuffer;
398401

399402
if( pxNewTimer != NULL )
400403
{
@@ -664,6 +667,9 @@
664667

665668
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0U )
666669
{
670+
/* MISRA Ref 11.3.1 [Misaligned access] */
671+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
672+
/* coverity[misra_c_2012_rule_11_3_violation] */
667673
*ppxTimerBuffer = ( StaticTimer_t * ) pxTimer;
668674
xReturn = pdTRUE;
669675
}

0 commit comments

Comments
 (0)