MISRA C Deviation Records

Project: Unicorn
Project version: 1.0.5
Guidelines: MISRA C 2012
Date: 19 February 2025

This document describes instances in which the code deviates from the MISRA C:2012 guidelines, categorized as Required. In accordance with Section 5.4 of the MISRA C:2012 guidelines, the report includes the following information for each deviation:


MISRA C:2012 Rule 17.2 Deviation Rationale

Summary

Functions shall not call themselves, either directly or indirectly. The rationale for MISRA C:2012 Rule 17.2 is that recursion carries with it the danger of exceeding available stack space, which can lead to a serious failure. Unless recursion is very tightly controlled, it is not possible to determine before execution what the worst-case stack usage could be.

Circumstances the Deviation is Permitted

This deviation is specific for single instances within individual files.

Justification for the Deviation

Certain algorithms are naturally implemented most efficiently and with the most clarity using recursion.

How Safety is Assured

The recursive functions operate on a fixed-size data set determined by a well-defined rule set from the Unicode consortium.

Consequences of Non-Conformance

Non-compliance with Rule 17.2, in this specific case, would not lead to any adverse consequences as the recursion is well-controlled and operates within known constraints.


MISRA C:2012 Rule 21.3 Deviation Rationale

Summary

The memory allocation and deallocation functions of <stdlib.h> shall not be used. The rationale for MISRA C:2012 Rule 17.2 is that Use of dynamic memory allocation and deallocation routines provided by The Standard Library can lead to undefined behavior. For example: memory that was not dynamically allocated is subsequently freed, a pointer to freed memory is used in any way, and accessing allocated memory before storing a value into it.

Circumstances the Deviation is Permitted

This deviation applies to the whole project.

Justification for the Deviation

Dynamic memory allocation is utilized where necessary to request additional memory from the host system to perform operations and execute algorithms. The implementation of memory allocation is considered essential for meeting project requirements.

How Safety is Assured

The code has a comprehensive test suite with 100% branch coverage. It is tested with memory, address, and undefined behavior sanitizers, as well as memory leak detection tools. Consumers of the code can also disable the Standard Library allocators or replace them with their own custom implementation if necessary.

Consequences of Non-Conformance

While the implementation is thoroughly tested, failure to comply with Rule 21.3 could lead to undefined behavior, such as memory leaks or invalid memory access, if defects are present in the implementation.