MISRA Compliance π
MISRA C is a widely accepted model for best practices used by automotive, telecom, aerospace, medical, and other critical industries. Unicorn honors all Mandatory, most Required, and most Advisory rules defined by MIRSA C:2012 and its amendments.
Conformance to most MISRA rules is verified with static analysis tools against the unamalgamated source code. Readers are encouraged to run their own static analysis tools against the public, amalgamated source code with the understanding that some false positives might be reported.
If you believe there is a MISRA violation and/or an inaccuracy in the compliance table, then please report it here.
Compliance Summary Table π
If Unicorn is compliant with a directive or rule then the Compliance column will begin with the text βCompliantβ optionally followed by the verification method in parentheses. If no verification method is listed, then static analysis is assumed (this is how most rules are verified). If Unicorn is non-compliant with a directive or rule then the Compliance column will begin with the text βNon-compliantβ in bold followed by documentation explaining why.
The MISRA C:2012 rule texts can not be freely distributed therefore the compliance summary table lists the rule number, but omits the description. It is assumed the reader has access to the MISRA C:2012 standard and can cross-reference the rule numbers with the standard.
Formal documentation:
Implementation π
Directive
|
Category
|
Compliance
|
D1.1
|
Required
|
Compliant (manually verified)
|
Compilation and Build π
Directive
|
Category
|
Compliance
|
D2.1
|
Required
|
Compliant (verified with GCC, Clang, and MSVC)
|
Requirements Traceability π
Directive
|
Category
|
Compliance
|
D3.1
|
Required
|
Compliant (manually verified)
|
Code Design π
Directive
|
Category
|
Compliance
|
D4.1
|
Required
|
Compliant (manually verified)
|
D4.2
|
Advisory
|
Compliant (Unicorn does not use assembly language)
|
D4.3
|
Required
|
Compliant
|
D4.4
|
Advisory
|
Compliant
|
D4.5
|
Advisory
|
Compliant
|
D4.6
|
Advisory
|
Compliant
|
D4.7
|
Required
|
Compliant (manually verified)
|
D4.8
|
Advisory
|
Non-compliant [1]
|
D4.9
|
Advisory
|
Compliant [2]
|
D4.10
|
Required
|
Compliant (manually verified)
|
D4.11
|
Required
|
Compliant (verified by unit tests)
|
D4.12
|
Required
|
Compliant (manually verified)
|
D4.13
|
Advisory
|
Compliant (manually verified)
|
[1] The programmatically generated Unicode data tables are collected into a single header/source amalgamation in the commercial implementation of Unicorn. The generated header is included by multiple translation units, but each translation unit only uses a subset of the generated definitions.
[2] Where a function-like macro should become a function is a trade-off between code size and execution speed. In Unicorn, most function-like macros are small expressions and programmatically generated.
Standard C Environment π
Rule
|
Category
|
Compliance
|
1.1
|
Required
|
Compliant
|
1.2
|
Advisory
|
Compliant
|
1.3
|
Required
|
Compliant
|
1.4
|
Required
|
Compliant
|
1.5
|
Required
|
Compliant
|
Unused Code π
Rule
|
Category
|
Compliance
|
2.1
|
Required
|
Compliant
|
2.2
|
Required
|
Compliant
|
2.3
|
Advisory
|
Compliant
|
2.4
|
Advisory
|
Compliant
|
2.5
|
Advisory
|
Compliant [1]
|
2.6
|
Advisory
|
Compliant
|
2.7
|
Advisory
|
Compliant
|
2.8
|
Advisory
|
Compliant
|
[1] Some macros in unicorn.h
are part of the public API, but are not used internally by the library. Static analysis tools may report these macros as being unused, but this is a false positive.
Comments π
Rule
|
Category
|
Compliance
|
3.1
|
Required
|
Compliant
|
3.2
|
Required
|
Compliant
|
Character Sets and Lexical Conventions π
Rule
|
Category
|
Compliance
|
4.1
|
Required
|
Compliant
|
4.2
|
Advisory
|
Compliant
|
Identifiers π
Rule
|
Category
|
Compliance
|
5.1
|
Required
|
Compliant
|
5.2
|
Required
|
Compliant
|
5.3
|
Required
|
Compliant
|
5.4
|
Required
|
Compliant
|
5.5
|
Required
|
Compliant
|
5.6
|
Required
|
Compliant
|
5.7
|
Required
|
Compliant
|
5.8
|
Required
|
Compliant
|
5.9
|
Advisory
|
Compliant
|
Rule
|
Category
|
Compliance
|
6.1
|
Required
|
Compliant
|
6.2
|
Required
|
Compliant
|
6.3
|
Required
|
Compliant
|
Literals and Constants π
Rule
|
Category
|
Compliance
|
7.1
|
Required
|
Compliant
|
7.2
|
Required
|
Compliant
|
7.3
|
Required
|
Compliant
|
7.4
|
Required
|
Compliant
|
7.5
|
Mandatory
|
Compliant
|
7.6
|
Required
|
Compliant
|
Declarations and Definitions π
Rule
|
Category
|
Compliance
|
8.1
|
Required
|
Compliant
|
8.2
|
Required
|
Compliant
|
8.3
|
Required
|
Compliant
|
8.4
|
Required
|
Compliant
|
8.5
|
Required
|
Compliant
|
8.6
|
Required
|
Compliant
|
8.7
|
Advisory
|
Compliant [1]
|
8.8
|
Required
|
Compliant
|
8.9
|
Advisory
|
Compliant
|
8.10
|
Required
|
Compliant
|
8.11
|
Advisory
|
Compliant
|
8.12
|
Required
|
Compliant
|
8.13
|
Advisory
|
Compliant
|
8.14
|
Required
|
Compliant
|
8.15
|
Required
|
Compliant
|
8.16
|
Advisory
|
Compliant
|
8.17
|
Advisory
|
Compliant
|
[1] This rule is not observed for the single header/source amalgamation (the public release). This is because the amalgamation combines all translation units into a single translation unit and does not update linkages in the process. The unamalgamated, MISRA compliant implementation is exclusively available to commercial licensees.
Initialization π
Rule
|
Category
|
Compliance
|
9.1
|
Mandatory
|
Compliant
|
9.2
|
Required
|
Compliant
|
9.3
|
Required
|
Compliant
|
9.4
|
Required
|
Compliant
|
9.5
|
Required
|
Compliant
|
9.6
|
Required
|
Compliant
|
9.7
|
Mandatory
|
Compliant
|
The Essential Type Modal π
Rule
|
Category
|
Compliance
|
10.1
|
Required
|
Compliant
|
10.2
|
Required
|
Compliant
|
10.3
|
Required
|
Compliant
|
10.4
|
Required
|
Compliant
|
10.5
|
Advisory
|
Compliant
|
10.6
|
Required
|
Compliant
|
10.7
|
Required
|
Compliant
|
10.8
|
Required
|
Compliant
|
Pointer Type Conversion π
Rule
|
Category
|
Compliance
|
11.1
|
Required
|
Compliant
|
11.2
|
Required
|
Compliant
|
11.3
|
Required
|
Compliant
|
11.4
|
Advisory
|
Compliant
|
11.5
|
Advisory
|
Non-compliant [1]
|
11.6
|
Required
|
Compliant
|
11.7
|
Required
|
Compliant
|
11.8
|
Required
|
Compliant
|
11.9
|
Required
|
Compliant
|
11.10
|
Required
|
Compliant
|
[1] In a few select locations Unicorn casts from a void*
to a uint8_t*
, uint16_t*
, or uint32_t*
. These casts are performed because Unicorn accepts encoded text as a void*
and must internally cast it to an integer pointer with the appropriate storage class. While Unicorn casts are known to be safe via unit testing the caller must ensure they specify the correct encoding form. Specifying the incorrect encoding form will result in a cast to an incorrect storage class resulting in undefined behavior.
Expressions π
Rule
|
Category
|
Compliance
|
12.1
|
Advisory
|
Compliant
|
12.2
|
Required
|
Compliant
|
12.3
|
Advisory
|
Compliant
|
12.4
|
Advisory
|
Compliant
|
12.5
|
Mandatory
|
Compliant
|
12.6
|
Required
|
Compliant
|
Side Effects π
Rule
|
Category
|
Compliance
|
13.1
|
Required
|
Compliant
|
13.2
|
Required
|
Compliant
|
13.3
|
Advisory
|
Compliant
|
13.4
|
Advisory
|
Compliant
|
13.5
|
Required
|
Compliant
|
13.6
|
Mandatory
|
Compliant
|
Control Statement Expressions π
Rule
|
Category
|
Compliance
|
14.1
|
Required
|
Compliant
|
14.2
|
Required
|
Compliant
|
14.3
|
Required
|
Compliant
|
14.4
|
Required
|
Compliant
|
Control Flow π
Rule
|
Category
|
Compliance
|
15.1
|
Advisory
|
Compliant
|
15.2
|
Required
|
Compliant
|
15.3
|
Required
|
Compliant
|
15.4
|
Advisory
|
Compliant
|
15.5
|
Advisory
|
Compliant
|
15.6
|
Required
|
Compliant
|
15.7
|
Required
|
Compliant [1]
|
[1] The unamalgamated implementation of Unicorn is compliant, however, the amalgmation is non-compliant because all comments are removed from it.
Switch Statements π
Rule
|
Category
|
Compliance
|
16.1
|
Required
|
Compliant
|
16.2
|
Required
|
Compliant
|
16.3
|
Required
|
Compliant
|
16.4
|
Required
|
Compliant
|
16.5
|
Required
|
Compliant
|
16.6
|
Required
|
Compliant
|
16.7
|
Required
|
Compliant
|
Functions π
Rule
|
Category
|
Compliance
|
17.1
|
Required
|
Compliant
|
17.2
|
Required
|
Non-compliant [1]
|
17.3
|
Mandatory
|
Compliant (verified via Clang)
|
17.4
|
Mandatory
|
Compliant
|
17.5
|
Advisory
|
Compliant
|
17.6
|
Mandatory
|
Compliant
|
17.7
|
Required
|
Compliant
|
17.8
|
Advisory
|
Compliant
|
17.9
|
Mandatory
|
Compliant
|
17.10
|
Required
|
Compliant
|
17.11
|
Advisory
|
Compliant
|
17.12
|
Advisory
|
Compliant
|
17.13
|
Required
|
Compliant
|
[1] Recursion is used when processing immutable pregenerated data structures. In these situations, the maximum recursion depth is shallow and known.
Pointers and Arrays π
Rule
|
Category
|
Compliance
|
18.1
|
Required
|
Compliant
|
18.2
|
Required
|
Compliant
|
18.3
|
Required
|
Compliant
|
18.4
|
Advisory
|
Compliant
|
18.5
|
Advisory
|
Compliant
|
18.6
|
Required
|
Compliant
|
18.7
|
Required
|
Compliant
|
18.8
|
Required
|
Compliant
|
18.9
|
Required
|
Compliant
|
18.10
|
Mandatory
|
Compliant
|
Overlapping Storage π
Rule
|
Category
|
Compliance
|
19.1
|
Mandatory
|
Compliant
|
19.2
|
Advisory
|
Compliant
|
Preprocessing Directives π
Rule
|
Category
|
Compliance
|
20.1
|
Advisory
|
Compliant
|
20.2
|
Required
|
Compliant
|
20.3
|
Required
|
Compliant
|
20.4
|
Required
|
Compliant
|
20.5
|
Advisory
|
Compliant
|
20.6
|
Required
|
Compliant
|
20.7
|
Required
|
Compliant
|
20.8
|
Required
|
Compliant
|
20.9
|
Required
|
Compliant
|
20.10
|
Advisory
|
Compliant
|
20.11
|
Required
|
Compliant
|
20.12
|
Required
|
Compliant
|
20.13
|
Required
|
Compliant
|
20.14
|
Required
|
Compliant
|
Standard Libraries π
Rule
|
Category
|
Compliance
|
21.1
|
Required
|
Compliant
|
21.2
|
Required
|
Compliant
|
21.3
|
Required
|
Non-compliant [1]
|
21.4
|
Required
|
Compliant
|
21.5
|
Required
|
Compliant
|
21.6
|
Required
|
Compliant
|
21.7
|
Required
|
Compliant
|
21.8
|
Required
|
Compliant
|
21.9
|
Required
|
Compliant
|
21.10
|
Required
|
Compliant
|
21.11
|
Required
|
Compliant
|
21.12
|
Advisory
|
Compliant
|
21.13
|
Mandatory
|
Compliant
|
21.14
|
Required
|
Compliant
|
21.15
|
Required
|
Compliant
|
21.16
|
Required
|
Compliant
|
21.17
|
Required
|
Compliant
|
21.18
|
Mandatory
|
Compliant
|
21.19
|
Mandatory
|
Compliant
|
21.20
|
Mandatory
|
Compliant
|
21.21
|
Required
|
Compliant
|
21.22
|
Mandatory
|
Compliant
|
21.23
|
Required
|
Compliant
|
21.24
|
Required
|
Compliant
|
21.25
|
Required
|
Compliant
|
21.26
|
Required
|
Compliant
|
[1] The realloc
and free
functions are present but optional.
Resources π
Rule
|
Category
|
Compliance
|
22.1
|
Required
|
Compliant
|
22.2
|
Mandatory
|
Compliant
|
22.3
|
Required
|
Compliant
|
22.4
|
Mandatory
|
Compliant
|
22.5
|
Mandatory
|
Compliant
|
22.6
|
Mandatory
|
Compliant
|
22.7
|
Required
|
Compliant
|
22.8
|
Required
|
Compliant
|
22.9
|
Required
|
Compliant
|
22.10
|
Required
|
Compliant
|
22.11
|
Required
|
Compliant
|
22.12
|
Mandatory
|
Compliant
|
22.13
|
Required
|
Compliant
|
22.14
|
Mandatory
|
Compliant
|
22.15
|
Required
|
Compliant
|
22.16
|
Required
|
Compliant
|
22.17
|
Required
|
Compliant
|
22.18
|
Required
|
Compliant
|
22.19
|
Required
|
Compliant
|
22.20
|
Mandatory
|
Compliant
|
Generic Selections π
Rule
|
Category
|
Compliance
|
23.1
|
Advisory
|
Compliant
|
23.2
|
Required
|
Compliant
|
23.3
|
Advisory
|
Compliant
|
23.4
|
Required
|
Compliant
|
23.5
|
Advisory
|
Compliant
|
23.6
|
Required
|
Compliant
|
23.7
|
Advisory
|
Compliant
|
23.8
|
Required
|
Compliant
|