Kiuwan logo

MISRA Guidelines for Software Development in C

Originally developed by the UK government’s “SafeIT” program and later expanded by the automotive industry, the Motor Industry Software Reliability Association (MISRA) sought to develop a C programming language subset — or “coding standard,” more colloquially — to govern their development processes. It’s grown from its inception in 1994 to include multiple sectors and has been updated repeatedly to reflect the current state of development, most recently in 2023. 

As software becomes increasingly critical in safety-sensitive industries, understanding and implementing MISRA guidelines has become essential for developers seeking to produce secure, maintainable, and portable code.

Here, we’ll explore the details of the MISRA standard in all its variations. We’ll look at both the MISRA C and MISRA C++ varieties and learn about which industries use MISRA the most. We’ll also survey the rules and guidelines within the MISRA coding standard, and how this framework can be used along with code analysis tools to elevate code security.

What Is MISRA? 

As vehicles relied increasingly upon electronics, automotive manufacturers realized the need for a single unifying standard to guide their coding practices. The result was MISRA.

Embedded programmers and experts from Ford Motor Company, Jaguar Land Rover, Bentley Motors, and other industry leaders collaborated to create a framework to help generate more uniform code, and their work was so successful that it was also implemented in many other sectors. The developers created MISRA to improve three coding parameters especially, namely:

  • Robustness: The ability to reliably execute under adverse conditions
  • Maintainability: The ease with which code can be updated or altered
  • Portability: The ability to work in different environments

Along with code security, these parameters are essential for many applications. So, industries that use the C/C++ programming languages looked to MISRA to help them create such premium code.

MISRA C 

As the programming language comprises the C and C++ variants, there is a separate MISRA code standard for both. Originally created in 1994, both versions have since undergone multiple revisions to reflect the latest best practices in code security and quality. The MISRA C standard was revised in 2004 and 2012. 

Several additions have been incorporated into the MISRA C framework since then, leading to the most recent adaptation in March 2023. This version, MISRA C:2023, includes the Technical Corrigendum 2, “Technical clarification of MISRA C:2012,” as well as the following amendments:

  • Amendment 1: “Additional Security Guidelines”
  • Amendment 2: “Updates for ISO/IEC 9899:2011/18 Core Functionality”
  • Amendment 3: “Updates for ISO/IEC 9899:2011/2018 Phase 2 — New C11/C18 features”
  • Amendment 4: “Updates for ISO/IEC 9899:2011/2018 Phase 3 — Multi-threading and Atomics”

Altogether, the MISRA C:2023 code standard offers developers a concise yet comprehensive framework for how they could best produce robust, maintainable, and portable high-security code. 

MISRA C++ and MISRA AC 

MISRA C++ is very similar to the MISRA C standard, except its rules are formed around the C++ programming language. Its most recent version was released to the public in October 2023 and covered many of the same topics as the MISRA C variant. Because of its frequent use in the automotive industry, MISRA C++:2023 also sought to incorporate the rules within the Automotive Open System Architecture (AUTOSAR) to reduce the number of discrepancies between the two. 

Because AI and automation are used to write code increasingly, the MISRA standard was also adapted to account for automatically generated code. MISRA AC AGC was created to inform automatic code generation practices. Its founding document is MISRA AC AGC: “Guidelines for the application of MISRA-C:2004 in the context of automatic code generation,” and its supporting resources are as follows:

  • MISRA AC INT: Introduction
  • MISRA AC GMG: Generic modelling design and style guidelines
  • MISRA AC SLSF: Modelling design and style guidelines for the application of Simulink and Stateflow
  • MISRA AC TL: Modelling style guidelines for the application of Target Link in the context of automatic code generation

While it was based upon the contents of MISRA C:2004, its rules also apply to C++. 

Who Uses MISRA?

MISRA’s widespread adoption across diverse industries underscores its versatility as a coding standard that enhances security and reliability in critical applications. The name may have reflected the standard’s original application, but MISRA has expanded so much that the “Motor Industry” portion no longer applies. MISRA has become the coding standard of choice for many industries that rely upon the programming languages C or C++:

  • Automotive
  • Aerospace and Defense
  • IoT
  • Finance
  • Agriculture
  • Energy
  • Healthcare
  • Telecommunications
  • Industrial Control Systems

The primary goal of MISRA is to make code written in the C/C++ programming languages more robust, portable, and maintainable. Wherever those factors are a priority, MISRA is often the framework of choice. 

MISRA Guidelines, Rules, and Directives

MISRA consists of a series of guidelines, which are divided into “rules” and “directives.” The latest MISRA standards contain a total of 200 guidelines comprising 182 rules and 18 directives. 

A rule is a guideline for which a complete description of the requirement has been provided. It should therefore be possible to check the source code for adherence to the rule with no other information than that which the rule provides. That is, code analysis tools such as static code analyzers can be automated to check your source code for compliance with MISRA Rules.

A directive is less explicit than a rule and is a guideline for which a complete description of the requirement is not feasible. This makes it harder to check directives for compliance with code analysis tools. While an exact description of each directive and rule wouldn’t be feasible here, ample resources such as compliance matrices exist to assist development teams with implementation. 

Don’t forget that leveraging automated tools like static code analyzers can help to ensure that your code remains compliant with MISRA rules by preventing errors and maintaining high standards of code quality.

Benefits of Using MISRA

MISRA was designed to improve code security, robustness, maintainability, and portability. However, some other benefits are as follows:

  • Earlier code issue detection
  • Faster code implementation
  • More accurate solutions
  • Faster vulnerability remediation
  • Higher code quality

Another key advantage of using MISRA is that it creates greater uniformity across a diverse tool of coding silos. A wide number of manufacturers and suppliers use the MISRA standard. So, using the same framework can reduce inconsistencies, further improving code quality and reducing your attack surface — which is what MISRA was designed for.

Final Thoughts

MISRA may have started in the automotive sector, but it’s since proven invaluable in improving the portability, security, and robustness of applications across many industries. Your development teams may use other frameworks to inform their code, but applications built upon the C programming languages that place a premium on code security should integrate MISRA into the mix.

MISRA has proven invaluable in enhancing the security, portability, and robustness of applications across industries. Integrating MISRA into your development process is crucial for any application built on C programming languages that prioritize security. Kiuwan’s static code analyzers make it easier to maintain compliance with MISRA standards, helping you build secure, high-quality software. Request a demo to see how Kiuwan can elevate your code security.

In This Article:

Request Your Free Kiuwan Demo Today!

Get Your FREE Demo of Kiuwan Application Security Today!

Identify and remediate vulnerabilities with fast and efficient scanning and reporting. We are compliant with all security standards and offer tailored packages to mitigate your cyber risk within the SDLC.

Related Posts

A Guide to Code Portability-updated

A Guide to Code Portability

As applications need to operate across multiple environments, code portability has emerged as a topic of focus for developers. This guide will help you understand what code portability is and…
Read more
© 2024 Kiuwan. All Rights Reserved.