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 #121

Merged
merged 15 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
39 changes: 20 additions & 19 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

The coreJSON 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:
The specific deviations, suppressed inline, 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 8.13 | Advisory | Allow one function to have a char * argument without const qualifier. |
| Rule 15.4 | Advisory | Allow more then one `break` statement to terminate a loop. |
| Rule 19.2 | Advisory | Allow a `union` of a signed and unsigned type of identical sizes. |
| Rule 20.12 | Required | Allow use of `assert()`, which uses a parameter in both expanded and raw forms. |

### 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/FreeRTOS/coreJSON/blob/main/tools/coverity/misra.config) contains the project wide deviations.

### Suppressed with Coverity Comments
| Deviation | Category | Justification |
| :-: | :-: | :-: |
| Rule 11.3 | Required | False positive - the rule permits type qualifiers to be added. |
To find the violation references in the source files run grep on the source code
with ( Assuming rule 14.3 violation; with justification in point 1 ):
```
grep 'MISRA Ref 14.3.1' . -rI
```

#### Rule 11.3
_Ref 11.3.1_

- MISRA C-2012 Rule 11.3 prohibits casting a pointer to a different type.
This instance is a false positive, as the rule permits the
addition of a const type qualifier.

#### Rule 14.3
_Ref 14.3.1_

- MISRA C-2012 Rule 14.3 False positive as the value might be changed
depending on the conditionally compiled code
2 changes: 2 additions & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ fd
fe
ff
ffff
freertos
foo
gcc
github
html
https
ifndef
Expand Down
8 changes: 5 additions & 3 deletions source/core_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ static bool skipOneHexEscape( const char * buf,

i = *start;
#define HEX_ESCAPE_LENGTH ( 6U ) /* e.g., \u1234 */
/* MISRA Ref 14.3.1 [Configuration dependent invariant] */
/* More details at: https://github.com/FreeRTOS/coreJSON/blob/main/MISRA.md#rule-143 */
/* coverity[misra_c_2012_rule_14_3_violation] */
end = ( i <= ( SIZE_MAX - HEX_ESCAPE_LENGTH ) ) ? ( i + HEX_ESCAPE_LENGTH ) : SIZE_MAX;

if( ( end < max ) && ( buf[ i ] == '\\' ) && ( buf[ i + 1U ] == 'u' ) )
Expand Down Expand Up @@ -1677,9 +1680,8 @@ JSONStatus_t JSON_SearchT( char * buf,
size_t * outValueLength,
JSONTypes_t * outType )
{
/* MISRA Rule 11.3 prohibits casting a pointer to a different type.
* This instance is a false positive, as the rule permits the
* addition of a type qualifier. */
/* MISRA Ref 11.3.1 [[Misaligned access]] */
/* More details at: https://github.com/FreeRTOS/coreJSON/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
return JSON_SearchConst( ( const char * ) buf, max, query, queryLength,
( const char ** ) outValue, outValueLength, outType );
Expand Down
28 changes: 23 additions & 5 deletions tools/coverity/misra.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,44 @@
category: "Advisory",
reason: "Allow inclusion of function like macros."
},
{
deviation: "Rule 2.5",
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 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.13",
category: "Advisory",
reason: "Allow one function to have a char * argument without const qualifier."
},
{
deviation: "Rule 12.3",
category: "Advisory",
reason: "Allow use of assert(), expansion of which uses comma operator."
},
{
deviation: "Rule 15.4",
category: "Advisory",
reason: "Allow more then one break statement to terminate a loop"
},
{
deviation: "Rule 15.6",
category: "Required",
reason: "Allow use of assert(), expansion of which contains non-compound if statements."
},
{
deviation: "Rule 19.2",
category: "Advisory",
reason: "Allow a union of a signed and unsigned type of identical sizes."
},
{
deviation: "Rule 3.1",
category: "Required",
reason: "Allow nested comments. Documentation blocks contain comments for example code."
},
{
deviation: "Rule 20.12",
category: "Required",
Expand Down