Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISRA Compliance Update #102

Merged
merged 7 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Deviations from the MISRA standard are listed below:
| Rule 2.4 | Advisory | Allow unused tags. Some compilers warn if types are not tagged. |
| Rule 2.5 | Advisory | Allow unused macros. Library headers may define macros intended for the application's use, but are not used by a specific file. |
| Rule 3.1 | Required | Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks. |
| Rule 8.7 | Advisory | API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application. |
| Rule 11.5 | Advisory | Allow casts from `void *`. Fields may be passed as `void *`, requiring a cast to the correct data type before use. |

### Flagged by Coverity
| Deviation | Category | Justification |
| :-: | :-: | :-: |
| Rule 8.7 | Advisory | API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application. |

### Suppressed with Coverity Comments
*None.*
36 changes: 18 additions & 18 deletions source/shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ static ShadowStatus_t validateMatchTopicParameters( const char * pTopic,
{
shadowStatus = SHADOW_BAD_PARAMETER;
LogError( ( "Invalid input parameters pTopic: %p, topicLength: %u, pMessageType: %p.",
( void * ) pTopic,
( unsigned int ) topicLength,
( void * ) pMessageType ) );
( const void * ) pTopic,
( uint16_t ) topicLength,
Skptak marked this conversation as resolved.
Show resolved Hide resolved
( const void * ) pMessageType ) );
}

return shadowStatus;
Expand All @@ -319,25 +319,25 @@ static ShadowStatus_t validateAssembleTopicParameters( ShadowTopicStringType_t t
{
LogError( ( "Invalid input parameters pTopicBuffer: %p, pThingName: %p, thingNameLength: %u,\
pShadowName: %p, shadowNameLength: %u, topicType: %d, pOutLength: %p.",
( void * ) pTopicBuffer,
( void * ) pThingName,
( unsigned int ) thingNameLength,
( void * ) pShadowName,
( unsigned int ) shadowNameLength,
( int ) topicType,
( void * ) pOutLength ) );
( const void * ) pTopicBuffer,
( const void * ) pThingName,
( uint8_t ) thingNameLength,
( const void * ) pShadowName,
( uint8_t ) shadowNameLength,
( uint32_t ) topicType,
( const void * ) pOutLength ) );
}
else if( thingNameLength > SHADOW_THINGNAME_MAX_LENGTH )
{
LogError( ( "Invalid thingNamelength. Thing name length of %u exceeds maximum allowed length %u.",
( unsigned int ) thingNameLength,
( unsigned int ) SHADOW_THINGNAME_MAX_LENGTH ) );
( uint8_t ) thingNameLength,
( uint32_t ) SHADOW_THINGNAME_MAX_LENGTH ) );
}
else if( shadowNameLength > SHADOW_NAME_MAX_LENGTH )
{
LogError( ( "Invalid shadowNameLength. Shadow name length of %u exceeds maximum allowed length %u.",
( unsigned int ) shadowNameLength,
( unsigned int ) SHADOW_NAME_MAX_LENGTH ) );
( uint8_t ) shadowNameLength,
( uint32_t ) SHADOW_NAME_MAX_LENGTH ) );
}
else
{
Expand Down Expand Up @@ -404,8 +404,8 @@ static ShadowStatus_t validateName( const char * pString,
{
LogDebug( ( "Not a Shadow topic. Extracted %s name length of %u exceeds maximum allowed length %u.",
( maxAllowedLength == SHADOW_THINGNAME_MAX_LENGTH ) ? "Thing" : "Shadow",
( unsigned int ) index,
( unsigned int ) maxAllowedLength ) );
( uint16_t ) index,
( uint8_t ) maxAllowedLength ) );
}
else
{
Expand Down Expand Up @@ -902,8 +902,8 @@ ShadowStatus_t Shadow_AssembleTopicString( ShadowTopicStringType_t topicType,
{
shadowStatus = SHADOW_BUFFER_TOO_SMALL;
LogError( ( "Input bufferSize too small, bufferSize %u, required %u.",
( unsigned int ) bufferSize,
( unsigned int ) generatedTopicStringLength ) );
( uint16_t ) bufferSize,
( uint16_t ) generatedTopicStringLength ) );
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ target_include_directories( coverity_analysis
${SHADOW_INCLUDE_PUBLIC_DIRS}
"${CMAKE_CURRENT_LIST_DIR}/include" )

target_compile_options(coverity_analysis PUBLIC -DDISABLE_LOGGING )

# ==================================== Test Configuration ========================================

# Define a CMock resource path.
Expand Down
18 changes: 18 additions & 0 deletions test/include/shadow_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,30 @@

#include <stdio.h>

#ifdef DISABLE_LOGGING
#ifndef LogError
#define LogError( message )
#endif
#ifndef LogWarn
#define LogWarn( message )
#endif

#ifndef LogInfo
#define LogInfo( message )
#endif

#ifndef LogDebug
#define LogDebug( message )
#endif

#else /* ! DISABLE_LOGGING */
#define LogError( message ) printf( "Error: " ); printf message; printf( "\n" )

Skptak marked this conversation as resolved.
Show resolved Hide resolved
#define LogWarn( message ) printf( "Warn: " ); printf message; printf( "\n" )

#define LogInfo( message ) printf( "Info: " ); printf message; printf( "\n" )

#define LogDebug( message ) printf( "Debug: " ); printf message; printf( "\n" )
#endif /* DISABLE_LOGGING */

#endif /* ifndef SHADOW_CONFIG_H_ */
4 changes: 4 additions & 0 deletions tools/misra.config → tools/coverity/misra.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
deviation: "Rule 3.1",
reason: "Allow nested comments. Documentation blocks contain comments for example code."
AniruddhaKanhere marked this conversation as resolved.
Show resolved Hide resolved
},
{
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 11.5",
reason: "Allow casts from void *. Contexts are passed as void * and must be cast to the correct data type before use."
Expand Down