Skip to content

Commit 94d1aac

Browse files
author
Ubuntu
committed
Fix MISRA C 2012 deviations
* Fix rule 18.6 deviations. Not to operaters on pointer. * Fix rule 9.1 deviations. Initialize the local variable to prevent use of uninitialized variable.
1 parent c5face5 commit 94d1aac

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

source/core_sntp_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static SntpStatus_t processServerResponse( SntpContext_t * pContext,
675675

676676
if( status == SntpSuccess )
677677
{
678-
SntpResponseData_t parsedResponse;
678+
SntpResponseData_t parsedResponse = { 0 };
679679

680680
/* De-serialize response packet to determine whether the server accepted or rejected
681681
* the request for time. Also, calculate the system clock offset if the server responded

source/core_sntp_serializer.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,14 @@ typedef struct SntpPacket
221221
static void fillWordMemoryInNetworkOrder( uint32_t * pWordMemory,
222222
uint32_t data )
223223
{
224+
uint8_t * pByteMemory = ( uint8_t * ) pWordMemory;
225+
224226
assert( pWordMemory != NULL );
225227

226-
*( ( uint8_t * ) pWordMemory ) = ( uint8_t ) ( data >> 24 );
227-
*( ( uint8_t * ) pWordMemory + 1 ) = ( uint8_t ) ( ( data >> 16 ) & 0x000000FFU );
228-
*( ( uint8_t * ) pWordMemory + 2 ) = ( uint8_t ) ( ( data >> 8 ) & 0x000000FFU );
229-
*( ( uint8_t * ) pWordMemory + 3 ) = ( uint8_t ) ( ( data ) & 0x000000FFU );
228+
pByteMemory[ 0 ] = ( uint8_t ) ( data >> 24 );
229+
pByteMemory[ 1 ] = ( uint8_t ) ( ( data >> 16 ) & 0x000000FFU );
230+
pByteMemory[ 2 ] = ( uint8_t ) ( ( data >> 8 ) & 0x000000FFU );
231+
pByteMemory[ 3 ] = ( uint8_t ) ( ( data ) & 0x000000FFU );
230232
}
231233

232234
/**
@@ -244,10 +246,10 @@ static uint32_t readWordFromNetworkByteOrderMemory( const uint32_t * ptr )
244246

245247
assert( ptr != NULL );
246248

247-
return ( uint32_t ) ( ( ( uint32_t ) *( pMemStartByte ) << 24 ) |
248-
( 0x00FF0000U & ( ( uint32_t ) *( pMemStartByte + 1 ) << 16 ) ) |
249-
( 0x0000FF00U & ( ( uint32_t ) *( pMemStartByte + 2 ) << 8 ) ) |
250-
( ( uint32_t ) *( pMemStartByte + 3 ) ) );
249+
return ( uint32_t ) ( ( ( uint32_t ) pMemStartByte[ 0 ] << 24 ) |
250+
( 0x00FF0000U & ( ( uint32_t ) pMemStartByte[ 1 ] << 16 ) ) |
251+
( 0x0000FF00U & ( ( uint32_t ) pMemStartByte[ 2 ] << 8 ) ) |
252+
( ( uint32_t ) pMemStartByte[ 3 ] ) );
251253
}
252254

253255
/**

tools/coverity/misra.config

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// MISRA C-2012 Rules
22

33
{
4-
version : "2.0",
5-
standard : "c2012",
6-
title: "Coverity MISRA Configuration",
7-
deviations : [
4+
"version" : "2.0",
5+
"standard" : "c2012",
6+
"title" : "Coverity MISRA Configuration",
7+
"deviations" : [
88
// Disable the following rules.
99
{
10-
deviation: "Directive 4.9",
11-
reason: "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
10+
"deviation": "Directive 4.9",
11+
"reason": "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
1212
},
1313
{
14-
deviation: "Rule 2.4",
15-
reason: "Allow unused tags. Some compilers warn if types are not tagged."
14+
"deviation": "Rule 2.4",
15+
"reason": "Allow unused tags. Some compilers warn if types are not tagged."
1616
},
1717
{
18-
deviation: "Rule 2.5",
19-
reason: "Allow unused macros. coreSNTP Library headers define macros intended for the application's use, but are not used by the agent."
18+
"deviation": "Rule 2.5",
19+
"reason": "Allow unused macros. coreSNTP Library headers define macros intended for the application's use, but are not used by the agent."
2020
},
2121
{
22-
deviation: "Rule 3.1",
23-
reason: "Allow nested comments. Documentation blocks contain comments for example code."
22+
"deviation": "Rule 3.1",
23+
"reason": "Allow nested comments. Documentation blocks contain comments for example code."
2424
},
2525
{
26-
deviation: "Rule 8.7",
27-
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
26+
"deviation": "Rule 8.7",
27+
"reason": "API functions are not used by library. They must be externally visible in order to be used by the application."
2828
},
2929
]
3030
}

0 commit comments

Comments
 (0)