diff --git a/MISRA.md b/MISRA.md index 08648c49..6e7c291d 100644 --- a/MISRA.md +++ b/MISRA.md @@ -1,24 +1,16 @@ - # MISRA Compliance The jobs library files conform to the [MISRA C:2012](https://www.misra.org.uk) guidelines, with some noted exceptions. Compliance is checked with Coverity static analysis. -Deviations from the MISRA standard are listed below: - -### Ignored by [Coverity Configuration](tools/coverity/misra.config) -| Deviation | Category | Justification | -| :-: | :-: | :-: | -| Directive 4.9 | Advisory | Allow inclusion of function like macros. | -| Rule 3.1 | Required | Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks. | -| Rule 20.12 | Required | Allow use of `assert()`, which uses a parameter in both expanded and raw forms. | +The specific deviations, suppressed inline, are listed below. -### Flagged by Coverity -| Deviation | Category | Justification | -| :-: | :-: | :-: | -| Rule 2.5 | Advisory | A macro is not used by the library; however, it exists to be used by an application. | -| Rule 8.7 | Advisory | API functions are not used by the library; however, they must be externally visible in order to be used by an application. | +Additionally, [MISRA configuration file](https://github.com/aws/Jobs-for-AWS-IoT-embedded-sdk/blob/main/tools/coverity/misra.config) contains the project wide deviations. ### Suppressed with Coverity Comments -| Deviation | Category | Justification | -| :-: | :-: | :-: | -| Rule 10.1 | Required | A variable of an enum type is used to iterate over contiguous values. | +To find the violation references in the source files run grep on the source code +with ( Assuming rule 11.4 violation; with justification in point 2 ): +``` +grep 'MISRA Ref 11.1.4' . -rI +``` + +*None.* diff --git a/docs/doxygen/include/size_table.md b/docs/doxygen/include/size_table.md index 2bde3b1d..9e1bdf26 100644 --- a/docs/doxygen/include/size_table.md +++ b/docs/doxygen/include/size_table.md @@ -9,12 +9,12 @@ jobs.c -
1.8K
-
1.5K
+
1.9K
+
1.6K
Total estimates -
1.8K
-
1.5K
+
1.9K
+
1.6K
diff --git a/source/jobs.c b/source/jobs.c index 38eed084..5db1faaf 100644 --- a/source/jobs.c +++ b/source/jobs.c @@ -430,21 +430,35 @@ static JobsStatus_t matchIdApi( char * topic, if( ( isNextJobId( jobId, jobIdLength ) == true ) || ( isValidJobId( jobId, jobIdLength ) == true ) ) { - JobsTopic_t api; - - /* The api variable is bounded within contiguous values of the enum type. */ - /* coverity[misra_c_2012_rule_10_1_violation] */ - for( api = JobsDescribeSuccess; api < JobsMaxTopic; api++ ) + if( JobsSuccess == strnnEq( p, length, apiTopic[ JobsDescribeSuccess ], apiTopicLength[ JobsDescribeSuccess ] ) ) + { + ret = JobsSuccess; + *outApi = JobsDescribeSuccess; + } + else if( JobsSuccess == strnnEq( p, length, apiTopic[ JobsDescribeFailed ], apiTopicLength[ JobsDescribeFailed ] ) ) + { + ret = JobsSuccess; + *outApi = JobsDescribeFailed; + } + else if( JobsSuccess == strnnEq( p, length, apiTopic[ JobsUpdateSuccess ], apiTopicLength[ JobsUpdateSuccess ] ) ) + { + ret = JobsSuccess; + *outApi = JobsUpdateSuccess; + } + else if( JobsSuccess == strnnEq( p, length, apiTopic[ JobsUpdateFailed ], apiTopicLength[ JobsUpdateFailed ] ) ) + { + ret = JobsSuccess; + *outApi = JobsUpdateFailed; + } + else { - ret = strnnEq( p, length, apiTopic[ api ], apiTopicLength[ api ] ); + /* MISRA Empty Body */ + } - if( ret == JobsSuccess ) - { - *outApi = api; - *outJobId = jobId; - *outJobIdLength = jobIdLength; - break; - } + if( ret == JobsSuccess ) + { + *outJobId = jobId; + *outJobIdLength = jobIdLength; } } @@ -471,23 +485,44 @@ static JobsStatus_t matchApi( char * topic, uint16_t * outJobIdLength ) { JobsStatus_t ret = JobsNoMatch; - JobsTopic_t api; assert( ( topic != NULL ) && ( outApi != NULL ) && ( outJobId != NULL ) && ( outJobIdLength != NULL ) ); /* The first set of APIs do not have job IDs. */ - /* The api variable is bounded within contiguous values of the enum type. */ - /* coverity[misra_c_2012_rule_10_1_violation] */ - for( api = JobsJobsChanged; api < JobsDescribeSuccess; api++ ) + if( JobsSuccess == strnnEq( topic, topicLength, apiTopic[ JobsJobsChanged ], apiTopicLength[ JobsJobsChanged ] ) ) { - ret = strnnEq( topic, topicLength, apiTopic[ api ], apiTopicLength[ api ] ); - - if( ret == JobsSuccess ) - { - *outApi = api; - break; - } + ret = JobsSuccess; + *outApi = JobsJobsChanged; + } + else if( JobsSuccess == strnnEq( topic, topicLength, apiTopic[ JobsNextJobChanged ], apiTopicLength[ JobsNextJobChanged ] ) ) + { + ret = JobsSuccess; + *outApi = JobsNextJobChanged; + } + else if( JobsSuccess == strnnEq( topic, topicLength, apiTopic[ JobsGetPendingSuccess ], apiTopicLength[ JobsGetPendingSuccess ] ) ) + { + ret = JobsSuccess; + *outApi = JobsGetPendingSuccess; + } + else if( JobsSuccess == strnnEq( topic, topicLength, apiTopic[ JobsGetPendingFailed ], apiTopicLength[ JobsGetPendingFailed ] ) ) + { + ret = JobsSuccess; + *outApi = JobsGetPendingFailed; + } + else if( JobsSuccess == strnnEq( topic, topicLength, apiTopic[ JobsStartNextSuccess ], apiTopicLength[ JobsStartNextSuccess ] ) ) + { + ret = JobsSuccess; + *outApi = JobsStartNextSuccess; + } + else if( JobsSuccess == strnnEq( topic, topicLength, apiTopic[ JobsStartNextFailed ], apiTopicLength[ JobsStartNextFailed ] ) ) + { + ret = JobsSuccess; + *outApi = JobsStartNextFailed; + } + else + { + /* MISRA Empty Body */ } /* The remaining APIs must have a job ID. */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f564ee09..e01519ea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,6 +41,8 @@ add_library( coverity_analysis # JOBS public include path. target_include_directories( coverity_analysis PUBLIC ${JOBS_INCLUDE_PUBLIC_DIRS} ) +# Build HTTP library target without logging +target_compile_options(coverity_analysis PUBLIC -DNDEBUG ) # ==================================== Test Configuration ======================================== # Include Unity build configuration. diff --git a/tools/coverity/misra.config b/tools/coverity/misra.config index fded4098..daac76e1 100644 --- a/tools/coverity/misra.config +++ b/tools/coverity/misra.config @@ -10,15 +10,19 @@ category: "Advisory", reason: "Allow inclusion of function like macros." }, + { + deviation: "Rule 2.5", + category: "Advisory", + reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file." + }, { deviation: "Rule 3.1", category: "Required", reason: "Allow nested comments. Documentation blocks contain comments for example code." }, { - deviation: "Rule 20.12", - category: "Required", - reason: "Allow use of assert(), which uses a parameter in both expanded and raw forms." - }, + 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." + } ] }