Skip to content

Commit 98c1989

Browse files
committed
Fix _socketSetSockOptLevelTransport alignment issues
Copy value rather than casting to avoid pointer alignment issues.
1 parent 5d76e3b commit 98c1989

2 files changed

Lines changed: 4 additions & 23 deletions

File tree

MISRA.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ _Ref 10.8.1_
7575
and isdigit. We do not have control over these so we are suppressing these
7676
violations.
7777

78-
#### Rule 11.3
79-
80-
_Ref 11.3.1_
81-
82-
- MISRA C-2012 Rule 11.3 does not allow casting of a pointer to different object
83-
types. We are passing in a length variable which is then checked to determine
84-
what to cast this value to. As such we are not worried about the chance of
85-
misaligned access when using the cast variable.
86-
8778
#### Rule 21.6
8879

8980
_Ref 21.6.1_

source/cellular_common_api.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o
7373
{
7474
if( optionValueLength == sizeof( uint32_t ) )
7575
{
76-
/* MISRA Ref 11.3 [Misaligned access] */
77-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
78-
/* coverity[misra_c_2012_rule_11_3_violation] */
79-
pTimeoutMs = ( const uint32_t * ) pOptionValue;
80-
socketHandle->sendTimeoutMs = *pTimeoutMs;
76+
( void ) memcpy( &( socketHandle->sendTimeoutMs ), pOptionValue, sizeof( uint32_t ) );
8177
}
8278
else
8379
{
@@ -88,11 +84,8 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o
8884
{
8985
if( optionValueLength == sizeof( uint32_t ) )
9086
{
91-
/* MISRA Ref 11.3 [Misaligned access] */
92-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
93-
/* coverity[misra_c_2012_rule_11_3_violation] */
94-
pTimeoutMs = ( const uint32_t * ) pOptionValue;
95-
socketHandle->recvTimeoutMs = *pTimeoutMs;
87+
( void ) memcpy( &( socketHandle->recvTimeoutMs ), pOptionValue, sizeof( uint32_t ) );
88+
9689
}
9790
else
9891
{
@@ -116,10 +109,7 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o
116109
{
117110
if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint16_t ) ) )
118111
{
119-
/* MISRA Ref 11.3 [Misaligned access] */
120-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
121-
/* coverity[misra_c_2012_rule_11_3_violation] */
122-
socketHandle->localPort = *( ( uint16_t * ) pOptionValue );
112+
( void ) memcpy( &( socketHandle->localPort ), pOptionValue, sizeof( uint16_t ) );
123113
}
124114
else
125115
{

0 commit comments

Comments
 (0)