Skip to content

Commit dc1ab91

Browse files
Fix 2 MISRA violations (#156)
1 parent b92c8cd commit dc1ab91

File tree

3 files changed

+77
-70
lines changed

3 files changed

+77
-70
lines changed

Diff for: source/core_json.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ static bool skipDigits( const char * buf,
688688
{
689689
bool ret = false;
690690
size_t i = 0U, saveStart = 0U;
691-
int32_t value = 0U;
691+
int32_t value = 0;
692692

693693
assert( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
694694

@@ -1711,11 +1711,10 @@ JSONStatus_t JSON_SearchT( char * buf,
17111711
size_t * outValueLength,
17121712
JSONTypes_t * outType )
17131713
{
1714-
/* MISRA Ref 11.3.1 [Misaligned access] */
1714+
/* MISRA Ref 11.3.1 [Pointer conversion] */
17151715
/* More details at: https://github.com/FreeRTOS/coreJSON/blob/main/MISRA.md#rule-113 */
17161716
/* coverity[misra_c_2012_rule_11_3_violation] */
1717-
return JSON_SearchConst( ( const char * ) buf, max, query, queryLength,
1718-
( const char ** ) outValue, outValueLength, outType );
1717+
return JSON_SearchConst( ( const char * ) buf, max, query, queryLength, ( const char ** ) outValue, outValueLength, outType );
17191718
}
17201719

17211720
/** @cond DO_NOT_DOCUMENT */

Diff for: test/CMakeLists.txt

+50-40
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "coreJSON source root."
2121
set( UNIT_TEST_DIR ${MODULE_ROOT_DIR}/test/unit-test CACHE INTERNAL "coreJSON unit test directory." )
2222
set( UNITY_DIR ${UNIT_TEST_DIR}/Unity CACHE INTERNAL "Unity library source directory." )
2323

24+
# If no configuration is defined, turn everything on.
25+
if( NOT DEFINED COV_ANALYSIS AND NOT DEFINED UNITTEST )
26+
set( COV_ANALYSIS TRUE )
27+
set( UNITTEST TRUE )
28+
endif()
29+
2430
# Configure options to always show in CMake GUI.
2531
option( BUILD_CLONE_SUBMODULES
2632
"Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned."
@@ -33,54 +39,58 @@ set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
3339

3440
# ================================ Coverity Analysis Configuration =================================
3541

36-
# Include filepaths for source and include.
37-
include( ${MODULE_ROOT_DIR}/jsonFilePaths.cmake )
38-
# Target for Coverity analysis that builds the library.
39-
add_library( coverity_analysis
40-
${JSON_SOURCES} )
41-
# JSON public include path.
42-
target_include_directories( coverity_analysis PUBLIC ${JSON_INCLUDE_PUBLIC_DIRS} )
43-
44-
# When building the coverity analysis target we disable debug
45-
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
42+
if( COV_ANALYSIS )
43+
# Include filepaths for source and include.
44+
include( ${MODULE_ROOT_DIR}/jsonFilePaths.cmake )
45+
# Target for Coverity analysis that builds the library.
46+
add_library( coverity_analysis
47+
${JSON_SOURCES} )
48+
# JSON public include path.
49+
target_include_directories( coverity_analysis PUBLIC ${JSON_INCLUDE_PUBLIC_DIRS} )
50+
51+
# When building the coverity analysis target we disable debug
52+
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
53+
endif()
4654

4755
# ==================================== Test Configuration ========================================
4856

49-
# Include Unity build configuration.
50-
include( unit-test/unity_build.cmake )
51-
52-
# Check if the Unity source directory exists, and if not present, clone the submodule
53-
# if BUILD_CLONE_SUBMODULES configuration is enabled.
54-
if( NOT EXISTS ${UNITY_DIR}/src )
55-
# Attempt to clone Unity.
56-
if( ${BUILD_CLONE_SUBMODULES} )
57-
clone_unity()
58-
else()
59-
message( FATAL_ERROR "The required submodule Unity does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
57+
if( UNITTEST )
58+
# Include Unity build configuration.
59+
include( unit-test/unity_build.cmake )
60+
61+
# Check if the Unity source directory exists, and if not present, clone the submodule
62+
# if BUILD_CLONE_SUBMODULES configuration is enabled.
63+
if( NOT EXISTS ${UNITY_DIR}/src )
64+
# Attempt to clone Unity.
65+
if( ${BUILD_CLONE_SUBMODULES} )
66+
clone_unity()
67+
else()
68+
message( FATAL_ERROR "The required submodule Unity does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
69+
endif()
6070
endif()
61-
endif()
6271

63-
# Add unit test and coverage configuration.
72+
# Add unit test and coverage configuration.
6473

65-
# Use CTest utility for managing test runs. This has to be added BEFORE
66-
# defining test targets with add_test()
67-
enable_testing()
74+
# Use CTest utility for managing test runs. This has to be added BEFORE
75+
# defining test targets with add_test()
76+
enable_testing()
6877

69-
# Add build targets for Unity and Unit, required for unit testing.
70-
add_unity_targets()
78+
# Add build targets for Unity and Unit, required for unit testing.
79+
add_unity_targets()
7180

72-
# Add function to enable Unity based tests and coverage.
73-
include( ${MODULE_ROOT_DIR}/tools/unity/create_test.cmake )
81+
# Add function to enable Unity based tests and coverage.
82+
include( ${MODULE_ROOT_DIR}/tools/unity/create_test.cmake )
7483

75-
# Include build configuration for unit tests.
76-
add_subdirectory( unit-test )
84+
# Include build configuration for unit tests.
85+
add_subdirectory( unit-test )
7786

78-
# ==================================== Coverage Analysis configuration ============================
87+
# ==================================== Coverage Analysis configuration ============================
7988

80-
# Add a target for running coverage on tests.
81-
add_custom_target( coverage
82-
COMMAND ${CMAKE_COMMAND} -DUNITY_DIR=${UNITY_DIR}
83-
-P ${MODULE_ROOT_DIR}/tools/unity/coverage.cmake
84-
DEPENDS unity core_json_utest
85-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
86-
)
89+
# Add a target for running coverage on tests.
90+
add_custom_target( coverage
91+
COMMAND ${CMAKE_COMMAND} -DUNITY_DIR=${UNITY_DIR}
92+
-P ${MODULE_ROOT_DIR}/tools/unity/coverage.cmake
93+
DEPENDS unity core_json_utest
94+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
95+
)
96+
endif()

Diff for: tools/coverity/misra.config

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
// MISRA C-2012 Rules
2-
31
{
4-
version : "2.0",
5-
standard : "c2012",
6-
title: "Coverity MISRA Configuration",
7-
deviations : [
2+
"version" : "2.0",
3+
"standard" : "c2012",
4+
"title": "Coverity MISRA Configuration",
5+
"deviations" : [
86
{
9-
deviation: "Directive 4.9",
10-
category: "Advisory",
11-
reason: "Allow inclusion of function like macros."
7+
"deviation": "Directive 4.9",
8+
"category": "Advisory",
9+
"reason": "Allow inclusion of function like macros."
1210
},
1311
{
14-
deviation: "Rule 2.5",
15-
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
12+
"deviation": "Rule 2.5",
13+
"reason": "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
1614
},
1715
{
18-
deviation: "Rule 3.1",
19-
category: "Required",
20-
reason: "Allow nested comments. Documentation blocks contain comments for example code."
16+
"deviation": "Rule 3.1",
17+
"category": "Required",
18+
"reason": "Allow nested comments. Documentation blocks contain comments for example code."
2119
},
2220
{
23-
deviation: "Rule 8.7",
24-
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
21+
"deviation": "Rule 8.7",
22+
"reason": "API functions are not used by library. They must be externally visible in order to be used by the application."
2523
},
2624
{
27-
deviation: "Rule 8.13",
28-
category: "Advisory",
29-
reason: "Allow one function to have a char * argument without const qualifier."
25+
"deviation": "Rule 8.13",
26+
"category": "Advisory",
27+
"reason": "Allow one function to have a char * argument without const qualifier."
3028
},
3129
{
32-
deviation: "Rule 15.4",
33-
category: "Advisory",
34-
reason: "Allow more then one break statement to terminate a loop"
30+
"deviation": "Rule 15.4",
31+
"category": "Advisory",
32+
"reason": "Allow more then one break statement to terminate a loop"
3533
},
3634
{
37-
deviation: "Rule 19.2",
38-
category: "Advisory",
39-
reason: "Allow a union of a signed and unsigned type of identical sizes."
40-
},
35+
"deviation": "Rule 19.2",
36+
"category": "Advisory",
37+
"reason": "Allow a union of a signed and unsigned type of identical sizes."
38+
}
4139
]
4240
}

0 commit comments

Comments
 (0)