Skip to content

Commit

Permalink
Fix MISRA C 2012 deviations
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Ubuntu committed Feb 21, 2024
1 parent c5face5 commit 94d1aac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion source/core_sntp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ static SntpStatus_t processServerResponse( SntpContext_t * pContext,

if( status == SntpSuccess )
{
SntpResponseData_t parsedResponse;
SntpResponseData_t parsedResponse = { 0 };

/* De-serialize response packet to determine whether the server accepted or rejected
* the request for time. Also, calculate the system clock offset if the server responded
Expand Down
18 changes: 10 additions & 8 deletions source/core_sntp_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,14 @@ typedef struct SntpPacket
static void fillWordMemoryInNetworkOrder( uint32_t * pWordMemory,
uint32_t data )
{
uint8_t * pByteMemory = ( uint8_t * ) pWordMemory;

assert( pWordMemory != NULL );

*( ( uint8_t * ) pWordMemory ) = ( uint8_t ) ( data >> 24 );
*( ( uint8_t * ) pWordMemory + 1 ) = ( uint8_t ) ( ( data >> 16 ) & 0x000000FFU );
*( ( uint8_t * ) pWordMemory + 2 ) = ( uint8_t ) ( ( data >> 8 ) & 0x000000FFU );
*( ( uint8_t * ) pWordMemory + 3 ) = ( uint8_t ) ( ( data ) & 0x000000FFU );
pByteMemory[ 0 ] = ( uint8_t ) ( data >> 24 );
pByteMemory[ 1 ] = ( uint8_t ) ( ( data >> 16 ) & 0x000000FFU );
pByteMemory[ 2 ] = ( uint8_t ) ( ( data >> 8 ) & 0x000000FFU );
pByteMemory[ 3 ] = ( uint8_t ) ( ( data ) & 0x000000FFU );
}

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

assert( ptr != NULL );

return ( uint32_t ) ( ( ( uint32_t ) *( pMemStartByte ) << 24 ) |
( 0x00FF0000U & ( ( uint32_t ) *( pMemStartByte + 1 ) << 16 ) ) |
( 0x0000FF00U & ( ( uint32_t ) *( pMemStartByte + 2 ) << 8 ) ) |
( ( uint32_t ) *( pMemStartByte + 3 ) ) );
return ( uint32_t ) ( ( ( uint32_t ) pMemStartByte[ 0 ] << 24 ) |
( 0x00FF0000U & ( ( uint32_t ) pMemStartByte[ 1 ] << 16 ) ) |
( 0x0000FF00U & ( ( uint32_t ) pMemStartByte[ 2 ] << 8 ) ) |
( ( uint32_t ) pMemStartByte[ 3 ] ) );
}

/**
Expand Down
28 changes: 14 additions & 14 deletions tools/coverity/misra.config
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// MISRA C-2012 Rules

{
version : "2.0",
standard : "c2012",
title: "Coverity MISRA Configuration",
deviations : [
"version" : "2.0",
"standard" : "c2012",
"title" : "Coverity MISRA Configuration",
"deviations" : [
// Disable the following rules.
{
deviation: "Directive 4.9",
reason: "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
"deviation": "Directive 4.9",
"reason": "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
},
{
deviation: "Rule 2.4",
reason: "Allow unused tags. Some compilers warn if types are not tagged."
"deviation": "Rule 2.4",
"reason": "Allow unused tags. Some compilers warn if types are not tagged."
},
{
deviation: "Rule 2.5",
reason: "Allow unused macros. coreSNTP Library headers define macros intended for the application's use, but are not used by the agent."
"deviation": "Rule 2.5",
"reason": "Allow unused macros. coreSNTP Library headers define macros intended for the application's use, but are not used by the agent."
},
{
deviation: "Rule 3.1",
reason: "Allow nested comments. Documentation blocks contain comments for example code."
"deviation": "Rule 3.1",
"reason": "Allow nested comments. Documentation blocks contain comments for example code."
},
{
deviation: "Rule 8.7",
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
"deviation": "Rule 8.7",
"reason": "API functions are not used by library. They must be externally visible in order to be used by the application."
},
]
}

0 comments on commit 94d1aac

Please sign in to comment.