Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ with ( Assuming rule 11.4 violation; with justification in point 2 ):
```
grep 'MISRA Ref 11.4.2' . -rI
```
#### Directive 4.12

_Ref 4.12.1_

- MISRA C:2012 Directive 4.12: Dynamic memory allocation shall not be used.
MISRA warns against the use of dynamic memory allocation as it might
lead to undefined behavior if not used properly. However, the
FreeRTOS-Plus-TCP library only uses the memory allocation primitives
defined by the FreeRTOS-Kernel, which are deterministic. Additionally,
proper care is taken in the code to not use free'd pointers and to check
the validity of malloc'd memory before it is dereferenced or used.

#### Rule 2.2

_Ref 2.2.1_
Expand Down
4 changes: 4 additions & 0 deletions source/FreeRTOS_DNS_Callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
TickType_t uxIdentifier )
{
size_t lLength = strlen( pcHostName );

/* MISRA Ref 4.12.1 [Use of dynamic memory]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#directive-412. */
/* coverity[misra_c_2012_directive_4_12_violation] */
DNSCallback_t * pxCallback = ( ( DNSCallback_t * ) pvPortMalloc( sizeof( *pxCallback ) + lLength ) );

/* Translate from ms to number of clock ticks. */
Expand Down
16 changes: 13 additions & 3 deletions source/FreeRTOS_Sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain,
if( prvDetermineSocketSize( xDomain, xType, xProtocolCpy, &uxSocketSize ) == pdFAIL )
{
/* MISRA Ref 11.4.1 [Socket error and integer to pointer conversion] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
/* coverity[misra_c_2012_rule_11_4_violation] */
xReturn = FREERTOS_INVALID_SOCKET;
}
Expand All @@ -414,12 +414,16 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain,
* size depends on the type of socket: UDP sockets need less space. A
* define 'pvPortMallocSocket' will used to allocate the necessary space.
* By default it points to the FreeRTOS function 'pvPortMalloc()'. */

/* MISRA Ref 4.12.1 [Use of dynamic memory]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#directive-412. */
/* coverity[misra_c_2012_directive_4_12_violation] */
pxSocket = ( ( FreeRTOS_Socket_t * ) pvPortMallocSocket( uxSocketSize ) );

if( pxSocket == NULL )
{
/* MISRA Ref 11.4.1 [Socket error and integer to pointer conversion] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
/* coverity[misra_c_2012_rule_11_4_violation] */
xReturn = FREERTOS_INVALID_SOCKET;
iptraceFAILED_TO_CREATE_SOCKET();
Expand All @@ -433,7 +437,7 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain,
vPortFreeSocket( pxSocket );

/* MISRA Ref 11.4.1 [Socket error and integer to pointer conversion] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
/* coverity[misra_c_2012_rule_11_4_violation] */
xReturn = FREERTOS_INVALID_SOCKET;
iptraceFAILED_TO_CREATE_EVENT_GROUP();
Expand Down Expand Up @@ -528,6 +532,9 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain,
{
SocketSelect_t * pxSocketSet;

/* MISRA Ref 4.12.1 [Use of dynamic memory]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#directive-412. */
/* coverity[misra_c_2012_directive_4_12_violation] */
pxSocketSet = ( ( SocketSelect_t * ) pvPortMalloc( sizeof( *pxSocketSet ) ) );

if( pxSocketSet != NULL )
Expand Down Expand Up @@ -4235,6 +4242,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )

uxSize = ( sizeof( *pxBuffer ) + uxLength ) - sizeof( pxBuffer->ucArray );

/* MISRA Ref 4.12.1 [Use of dynamic memory]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#directive-412. */
/* coverity[misra_c_2012_directive_4_12_violation] */
pxBuffer = ( ( StreamBuffer_t * ) pvPortMallocLarge( uxSize ) );

if( pxBuffer == NULL )
Expand Down