mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Suppress MISRA C rule 11.3 in MISRA.md (#857)
Suppress MISRA C rule 11.3 in MISRA.md
This commit is contained in:
parent
f2637bae55
commit
dabbc05a39
19
MISRA.md
19
MISRA.md
|
@ -31,6 +31,25 @@ _Ref 8.4.1_
|
||||||
a declaration in header file is not useful as the assembly code will
|
a declaration in header file is not useful as the assembly code will
|
||||||
still need to declare it separately.
|
still need to declare it separately.
|
||||||
|
|
||||||
|
|
||||||
|
#### Rule 11.3
|
||||||
|
|
||||||
|
_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.
|
||||||
|
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 guaranteed to have the same size and alignment which is
|
||||||
|
checked using configASSERT.
|
||||||
|
|
||||||
|
|
||||||
### MISRA configuration
|
### MISRA configuration
|
||||||
|
|
||||||
Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
|
Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
|
||||||
|
|
|
@ -98,7 +98,10 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
|
||||||
#endif /* configASSERT_DEFINED */
|
#endif /* configASSERT_DEFINED */
|
||||||
|
|
||||||
/* The user has provided a statically allocated event group - use it. */
|
/* The user has provided a statically allocated event group - use it. */
|
||||||
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(). */
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
|
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer;
|
||||||
|
|
||||||
if( pxEventBits != NULL )
|
if( pxEventBits != NULL )
|
||||||
{
|
{
|
||||||
|
@ -710,6 +713,9 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
|
||||||
/* Check if the event group was statically allocated. */
|
/* Check if the event group was statically allocated. */
|
||||||
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
|
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
|
||||||
{
|
{
|
||||||
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
|
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
}
|
||||||
|
@ -721,6 +727,9 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
|
||||||
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
|
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||||
{
|
{
|
||||||
/* Event group must have been statically allocated. */
|
/* Event group must have been statically allocated. */
|
||||||
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
|
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
8
queue.c
8
queue.c
|
@ -408,7 +408,10 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
|
||||||
/* The address of a statically allocated queue was passed in, use it.
|
/* The address of a statically allocated queue was passed in, use it.
|
||||||
* The address of a statically allocated storage area was also passed in
|
* The address of a statically allocated storage area was also passed in
|
||||||
* but is already set. */
|
* but is already set. */
|
||||||
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. */
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
|
pxNewQueue = ( Queue_t * ) pxStaticQueue;
|
||||||
|
|
||||||
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
||||||
{
|
{
|
||||||
|
@ -459,6 +462,9 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
|
||||||
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
|
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
|
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,10 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||||
StreamBufferCallbackFunction_t pxSendCompletedCallback,
|
StreamBufferCallbackFunction_t pxSendCompletedCallback,
|
||||||
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )
|
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )
|
||||||
{
|
{
|
||||||
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
|
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer;
|
||||||
StreamBufferHandle_t xReturn;
|
StreamBufferHandle_t xReturn;
|
||||||
uint8_t ucFlags;
|
uint8_t ucFlags;
|
||||||
|
|
||||||
|
@ -466,7 +469,10 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||||
|
|
||||||
traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer );
|
traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer );
|
||||||
|
|
||||||
xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
|
xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -498,6 +504,9 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||||
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 )
|
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 )
|
||||||
{
|
{
|
||||||
*ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer;
|
*ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer;
|
||||||
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
*ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer;
|
*ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer;
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
8
tasks.c
8
tasks.c
|
@ -1271,7 +1271,10 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
|
||||||
{
|
{
|
||||||
/* The memory used for the task's TCB and stack are passed into this
|
/* The memory used for the task's TCB and stack are passed into this
|
||||||
* function - use them. */
|
* function - use them. */
|
||||||
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. */
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
|
pxNewTCB = ( TCB_t * ) pxTaskBuffer;
|
||||||
( void ) memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
|
( void ) memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
|
||||||
pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;
|
pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;
|
||||||
|
|
||||||
|
@ -4354,6 +4357,9 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
|
||||||
if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB )
|
if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB )
|
||||||
{
|
{
|
||||||
*ppuxStackBuffer = pxTCB->pxStack;
|
*ppuxStackBuffer = pxTCB->pxStack;
|
||||||
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
*ppxTaskBuffer = ( StaticTask_t * ) pxTCB;
|
*ppxTaskBuffer = ( StaticTask_t * ) pxTCB;
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
8
timers.c
8
timers.c
|
@ -394,7 +394,10 @@
|
||||||
|
|
||||||
/* A pointer to a StaticTimer_t structure MUST be provided, use it. */
|
/* A pointer to a StaticTimer_t structure MUST be provided, use it. */
|
||||||
configASSERT( pxTimerBuffer );
|
configASSERT( pxTimerBuffer );
|
||||||
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. */
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
|
pxNewTimer = ( Timer_t * ) pxTimerBuffer;
|
||||||
|
|
||||||
if( pxNewTimer != NULL )
|
if( pxNewTimer != NULL )
|
||||||
{
|
{
|
||||||
|
@ -664,6 +667,9 @@
|
||||||
|
|
||||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0U )
|
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0U )
|
||||||
{
|
{
|
||||||
|
/* MISRA Ref 11.3.1 [Misaligned access] */
|
||||||
|
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
|
||||||
|
/* coverity[misra_c_2012_rule_11_3_violation] */
|
||||||
*ppxTimerBuffer = ( StaticTimer_t * ) pxTimer;
|
*ppxTimerBuffer = ( StaticTimer_t * ) pxTimer;
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue