MISRA Compliance πŸ”—

MISRA C is a widely accepted model for best practices used by automotive, telecom, aerospace, medical devices, and others. Unicorn honors all Required, Mandatory, and most Advisory rules defined by MIRSA C:2012. This page documents compliance with MISRA C:2012 and documents all deviations.

Conformance to most MISRA rules is verified via the Cppcheck static analysis tool. Readers are encouraged to run their own static analysis tools to verify conformance and that noted deviations are acceptable.

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 Cppcheck 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 and documentation explaining why.

The MISRA C:2012 rule texts can't be freely distributed therefore the compliance summary table lists the rule number, but omits its description. It is assumed the reader has access to the MISRA C:2012 standard and can cross-reference the rule numbers with the standard.

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 (Unicorn does not use assembly language)
D4.4 Advisory Compliant (manually verified)
D4.5 Advisory Compliant (manually verified)
D4.6 Advisory Compliant (manually verified)
D4.7 Required Compliant (manually verified)
D4.8 Advisory Compliant (manually verified)
D4.9 Advisory Compliant (manually verified)
D4.10 Required Compliant (manually verified)
D4.11 Required Compliant (verified via unit tests)
D4.12 Required Compliant (manually verified)
D4.13 Advisory Compliant (manually verified)

Standard C Environment πŸ”—

Rule Category Compliance
1.1 Required Compliant
1.2 Required Compliant (verified by compiling with Clang's -pdentic flag)
1.3 Required Compliant (verified by Cppcheck and Clang's undefined behavior sanitizer)

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

[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

Types πŸ”—

Rule Category Compliance
6.1 Required Compliant
6.2 Required Compliant

Literals and Constants πŸ”—

Rule Category Compliance
7.1 Required Compliant
7.2 Required Compliant
7.3 Required Compliant
7.4 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.13 Advisory Compliant
8.14 Required 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

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.5 Advisory Compliant
11.6 Required Compliant
11.7 Required Compliant
11.8 Required Compliant
11.9 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 an 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

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

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

[1] Recusion is used when processing immutable pregenerated data structures. In these cases the maximum recursion depth is fixed.

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

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.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 Mandatory Compliant
21.18 Mandatory Compliant
21.19 Mandatory Compliant

[1] The realloc and free functions are present but optional.

Resources πŸ”—

Rule Category Compliance
22.1 Required Compliant
22.2 Mandatory Compliant
21.20 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