You are on page 1of 7

W H I T E PA P E R

What is MISRA? An Overview


of the MISRA Standard

You don’t have to take much interest in the world of embedded software before
you learn about coding standards and then become aware of MISRA C. A little
further in and you become aware that there is more to MISRA than just MISRA C.
This paper provides a quick overview of MISRA, coding standards and the role of
static analysis tools in the development of high quality code.

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)
WHITE PAPER

What is MISRA? An Overview of the MISRA Standard

Contents

Introduction........................................................... 3

C and C++............................................................. 3

Coding Standards................................................... 3

The MISRA Coding Guidelines.................................. 4

MISRA C:1998........................................................ 4

MISRA C:2004....................................................... 4

MISRA C++:2008................................................... 4

MISRA Autocoder................................................... 5

MISRA C:2012........................................................ 5

MISRA Safe and Secure............................................ 5

MISRA Compliance and Deviation Permits.................. 6

Static Analysis......................................................... 6

Summary............................................................... 7

About MISRA.......................................................... 7

Helix QAC and MISRA............................................. 7

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)
WHITE PAPER

3 | What is MISRA? An Overview of the MISRA Standard

Introduction virtually every processor. It provides a wide range of


resources and librairies, is supported by a wide range of
In the early 1990s it became obvious that electronics
tools, and there is a plentiful pool of developers.
were becoming increasingly important in cars, and
that software was becoming increasingly important
“Biocartis has used QAC and QAC++
in electronics. With this recognition came another
during the development of IEC 62304
understanding – that software reliability was an absolute
imperative for both commercial and safety reasons. Today compliant software (safety Class C) for
that challenge is even greater as the amount of software the Idylla™ IVD (medical) device. We ap-
within a car can now extend to as much as 100 million ply MISRA based coding guidelines and
lines of code. have been very impressed by the ability

MISRA (the Motor Industry Software Reliability


of QAC and QAC++ to find issues that
Association) is a consortium formed from representatives other tools miss and also the low level of
of different companies working in the automotive false positives (noise).”
industry. It was set up initially with some UK government
Yves Willems, Software Engineering
backing, to look at the challenges posed by the
Manager at Biocartis NV
increasing use of software in motor vehicles and to
provide guidance on how embedded software should C was designed as a small, high level language to
be developed. A steady stream of documents has replace assembler. It has since evolved to become an
been published addressing various aspects of software application language, but its suitability for use in safety-
engineering. One of the first, produced in 1994, was critical environments was never a primary consideration.
entitled “Development Guidelines for Vehicle Based A C program which compiles and conforms fully to the
Software”, an automotive-specific interpretation of the requirements of the ISO language standard may still
then emerging IEC 61508 standard, “Functional Safety include code which will exhibit completely unpredictable
of Electrical / Electronic / Programmable Electronic behavior - this is clearly unacceptable in an application
Safety-related Systems”. This document was effectively such as a car braking system! The dangers can be
superseded with the recent publication of the ISO 26262 substantially reduced by applying restrictions to the
standard, Road Vehicles, Functional Safety. way in which the language is used and this has been the
essential aim of the MISRA coding guidelines.
After the funded project ended, work continued on a
number of fronts but perhaps most significantly in the
development of coding standards. Working groups were
Coding Standards
established and, over the years, have published a series In their simplest form, coding standards are often created
of documents containing guidelines to address some of as a way of defining a set of consistent coding practices.
the problems inherent in the C and C++ languages. Although uniformity of style can be a valuable discipline
within a software project, such issues are frequently a
C and C++ matter of personal preference. They do not address the
important attributes of software quality such as reliability,
C and C++ are by some distance the most widely used
portability or maintainability. A more fundamental role
languages for embedded software development.
of coding standards is to define a safer sub-set of the
(Recent research by VDC shows C being used by 70%
programming language by framing a set of rules which
of the embedded systems companies surveyed and its
eliminate coding constructs known to be hazardous.
derivative, C++, in 42% .) C has been implemented for

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)
WHITE PAPER

4 | What is MISRA? An Overview of the MISRA Standard

The C language allows the developer to do many ingredient in a successful software development
things which are essentially incorrect. It is all too easy to process. Any programming project has to be integrated
write code which conforms to the requirements of the into a disciplined engineering environment, with a
language standard but which will result in either program documented development process and the use of
failure (i.e. a crash) or in undefined behaviour. Common appropriate compilers and validation tools.
examples might be code which results in accessing
memory outside the bounds of an array or an arithmetic “MISRA is a very sound coding guideline
operation which results in integer overflow. that is widely adopted by developers
Clearly it is of paramount importance to identify such
implementing safety critical designs
‘bugs’. Some may be identified by a compiler although across a wide variety of industries and
a dedicated static analysis tool will generally be far more applications”
effective. However the primary aim of coding rules is
Richard Burke, Software and
not generally the identification of such problems but
Systems Manager at Protean Electric
prevention. Rules which admonish the developer not
to make obvious “mistakes” are usually unhelpful and
may even provoke derision! The fundamental aim of a
MISRA C:1998
coding rule should be to restrict use of the language so The first set of coding guidelines published by MISRA
as to prevent the developer from doing things which appeared in 1998. Two MISRA members, Ford and Rover,
are either intrinsically ‘wrong’ or potentially dangerous. had asked PRQA to help them to create their own coding
For example, it is possible in the C language to declare standards. This work formed the basis for what became
and define functions in two different ways. The ‘old’ the first edition of MISRA C: “Guidelines for the Use of
(Kernighan and Ritchie) syntax which was a feature of the C Language in Vehicle Based Software”. This version
early versions of the language is still supported but has contained 127 coding rules and it made an immediate
now been superseded by ‘function prototype’ syntax. impact. Some 13 years later, it is still being used in the
The use of K&R syntax is prohibited in MISRA-C simply maintenance of many legacy systems.
because it can so easily be misused and introduce
bugs. Many software defects can be avoided simply by MISRA C:2004
adopting some sensible restrictions on language use. As MISRA C became widely adopted, areas were
identified where it needed to be improved and clarified.
The MISRA Coding Guidelines A new version was published in 2004. It was structured
The MISRA coding guidelines are now accepted world- rather differently and contained a few additional rules
wide as the benchmarks for developing safety-critical but preserved the essential flavour of the original version.
software in C and C++. They have been widely accepted Significantly, the modified title referred to “critical
because they are concise and readable and because they systems” rather than just “vehicle based software” -
focus on essential issues. reflecting the fact that MISRA C was now widely used
outside the motor industry.
Each document contains a set of coding rules, but the
rules are preceded by several chapters of background
MISRA C++:2008
information that are just as important to anyone who
While C remains the dominant programming language
would like to develop robust code. The guidelines
in safety critical systems, there has been a steady
emphasize that adherence to coding rules is just one

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)
WHITE PAPER

5 | What is MISRA? An Overview of the MISRA Standard

increase in the use of C++. In response to popular This document has been deprecated and no longer
demand, a new working group was established and supported by MISRA from 1 June 2014. MISRA AC AGC
MISRA C++ appeared. will remain available and supported for legacy users
of MISRA C:2004. It should be noted that the current
MISRA Autocode version MISRA C:2012 integrates requirement for
automatically-generated C code.
One of the growth areas in systems development is
the use of modeling tools. Automatically generating
code from a model is a process that is fast and flexible,
MISRA C:2012
especially when it comes to incorporating changes later MORE COMMONLY KNOWN AS MISRA C3
in the product development cycle.
MISRA C:2012 was first published in April 2013 and
marks a further step forward in the development of the
“Haldex is keen to pursue “best practic-
MISRA C Guidelines. After 14 years of experience drawn
es” and has therefore chosen to adopt from many thousands of users and organisations, lessons
the MISRA C coding guidelines. This has are still being learned. This, the third edition, adds some
not been mandated by their customers, new rules, addresses some loopholes and improves
but rather Haldex see this as a key re- the description and explanation behind existing rules

quirement, and indeed a prerequisite to including some precise guidelines on how to deviate for
rules – not applicable for mandatory rules.
the development of high quality code for
safety-critical applications.” MISRA C:2012 extends support to the C99 version of
the C language (while maintaining guidelines for C90),
Dudley Harrison,
in addition to including a number of improvements that
Chief Engineer, Trailer Systems
can reduce the cost and complexity of compliance,
The application of coding guidelines in the context whilst aiding consistent, safe use of C in critical systems.
of automatically generated code can be a source Improvements, many of which have been made as a
of confusion. Rules developed for manual code result of user feedback, include: better rationales for
development are not always appropriate for auto every guideline, identified decidability so users can
generated code. MISRA has therefore published better interpret the output of checking tools, greater
additional guidelines which address the issue of how granularity of rules to allow more precise control, a
the MISRA-C:2004 rules should be applied in a code number of expanded examples and integration of
generation tool. MISRA AC AGC. A cross reference for ISO 26262 has
also been produced.
However, the quality of auto generated code is not the
sole responsibility of the code generation tool. It may MISRA Safe and Secure
also reflect the design of the model from which the code
There is a perception that MISRA C is only safety-related
has been generated, and so a number of documents
and not security related, as MISRA C defines a language
have also been published which provide design and style
subset. Safety –related standards require the use of a
guidelines in the application of modeling languages such
language subset, and thus MISRA C is associated with
as Simulink and Targetlink.
high integrity or high reliability requirements.
MISRA AC is now a few years old and far removed from
With the growing concern of the IoT (Internet of Things)
the current version of the tools offered by its vendors.
and to justify the viewpoint that MISRA C:2012 is equally

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)
WHITE PAPER

6 | What is MISRA? An Overview of the MISRA Standard

applicable to security–related applications, MISRA C It supersedes the compliance, deviation and process
carried out a coverage comparison in response to the requirements previously published in various MISRA
publication of ISO/IEC 17961:2013 – the C Language coding guidelines. Associated with this, MISRA
Security Guidelines published by the C standard C:2004 Permits (also published in April 2016) presents
committee (ISO/IEC JTC1/SC22/WG14). The result of a number of deviation permits covering commonly-
this comparison was published as Addendum 2 to MISRA encountered use cases for use with the MISRA C:2004
C:2012 which shows that for freestanding applications, guidelines. It should be used in conjunction with MISRA
MISRA C:2012 already had excellent coverage. Compliance:2016.

However, the comparison work highlighted a small


Static Analysis
number of areas where the MISRA C coding guidelines
could be enhanced and this resulted in MISRA C:2012 Unfortunately, the decision to adopt coding guidelines

Amendment 1. This amendment sets out new guidelines is frequently undermined by the practical difficulties

as an extension to MISRA C:2012 to improve the inherent in enforcing such a policy. It has been observed

coverage of the security concerns highlighted by the ISO that many companies invest considerable effort in

C Secure Guidelines.Several of these new guidelines compiling a set of coding guidelines only to find that the

address well known security vulnerabilities related to the document subsequently gathers dust on a shelf.

use of untrustworthy data.


“Selex ES recognizes the importance of
MISRA Compliance coding standards in generating robust
and Deviation Permits code, and has chosen to implement
In April 2016, MISRA C published MISRA a sub-set of MISRA rules, with some
Compliance:2016. This document which sets out a company specific extensions. Although
framework for achieving compliance with MISRA coding this standard was originally created for
guidelines and includes guidance on a robust and the automotive industry, the rule-set is
structured process for the use of deviations. a distillation of the work of some of the
Claiming compliance with MISRA has always been world’s leading coding experts and is
subject to debate, as it has been recognised that there equally suitable for (and widely adopt-
are occasions when it it is impracticable or unreasonable ed across) many other industries - in
to follow the requirements of a guideline. This leads to particular those that are developing
the concept of approved violations (deviations) and what
mission-critical and safety-critical solu-
the effect is on compliance. Many approaches have been
tions. For Selex ES the MISRA guidelines
used from no deviations allowed to using deviations for
served as an ideal starting point for an
any area that does not comply
application- and company-specific set of
MISRA Compliance:2016 aims to define what is meant coding standards.”
by MISRA Compliance, provides clearer guidelines
on the use of deviations and also a mechanism for Ian Anderson, Head of Software
modifying the classification of guidelines to match Engineering at Selex ES
the need of the project. It introduces the concept of
establishing pre-approved ‘permits’ to help streamline
the deviation process.

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)
WHITE PAPER

7 | What is MISRA? An Overview of the MISRA Standard

The MISRA coding guidelines recognize the fact that About MISRA
effective enforcement of coding rules can rarely be
More information about MISRA can be found at
achieved by manual code review. Traditional code
www.misra.org.uk
inspections are hugely time consuming and not always
reliable. However, most coding rules are amenable to
automatic enforcement with a tool.
Helix QAC and MISRA
The relationship between Helix QAC (formerly PRQA) and
Some embedded compilers provide a certain level of rule MISRA stretches back some 20 years. Major elements of
enforcement. Dedicated static analysis tools usually go both the MISRA C and MISRA C++ guidelines have been
much further; as well as identifying specific rule violations derived from our own coding standards and our technical
they may also identify other coding problems, calculate experts remain as key members of the MISRA C and
source code metrics or conduct an in-depth dataflow MISRA C++ working groups.
analysis of code to identify subtle run-time errors.
Helix QAC is recognized throughout the industry as a
Not every MISRA rule is automatically enforceable; champion in automated coding standard inspection
there are a handful of rules which address issues of and defect detection, delivering its expertise through
documentation or which are framed so as to require an industry-leading software inspection and standards
element of subjective judgment which a tool cannot enforcement technology.
provide. However the vast majority of MISRA rules can be
very effectively enforced automatically. Helix QAC is at the forefront in delivering MISRA C
and MISRA C++ compliance checking as well as a
Static code analysis is a technology which is fast, host of other valuable analysis capabilities. It contains
powerful, reliable and repeatable. Being a tool that can be powerful proprietary parsing engines combined with
exercised on the desktop by an individual programmer, it deep accurate dataflow, which deliver high fidelity
also avoids the confrontation and embarrassment which language analysis and comprehension. They identify
can easily be a feature of manual code reviews. problems caused by language usage that is dangerous,
overly complex, non-portable, or difficult to maintain.
Summary Additionally, they provide a mechanism for coding
Since publication of the first version of MISRA-C in standard enforcement.
1998, MISRA has established a reputation as a world
Helix QAC provides Compliance Modules for the
leader in developing coding standards for embedded
enforcement of MISRA C:1998, MISRA C:2004, and
software development.
MISRA C:2012 as well as MISRA C++:2008. The
C and C++ are not ideal languages for safety critical effectiveness of Helix QAC has been widely acclaimed —
code; but it is now widely accepted that they can be used see the independent research conducted by TERA-Labs (a
effectively to develop reliable software if a sub-set of the research division of the Karel de Grote University College,
language is defined in a coding standard and if static Antwerp, Belgium).
analysis tools are used to provide consistent enforcement.

About Perforce

With offices in Minneapolis, MN; Alameda, CA; the United Kingdom; Germany; and India, Perforce is a leader in software quality and testing
tools. Safety-critical industries across the globe trust Perforce’s static code analyzers — Helix QAC and Klocwork — to ensure that their code
is high-quality, safe and secure, error-free, and compliant. For more information, visit perforce.com.

www.perforce.com © Perforce Software, Inc. All trademarks and registered trademarks


are the property of their respective owners. (1020JB19)

You might also like