SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Outline
                        Introduction
      Reliability Coding Guidelines
                       Applications
                   Further readings




Misra C Software Development Standard

                        Vittorio Giovara

                         Politecnico di Torino


                  Software Engineering

                            03/10/2008



                   Vittorio Giovara    Misra C Software Development Standard
Outline
                                   Introduction
                 Reliability Coding Guidelines
                                  Applications
                              Further readings

Creative Common Licence v3.0 Attribution - ShareAlike
  You are free
      to copy, distribute, display, and perform the work
      to make derivative works
      to make commercial use of the work
  Under the following conditions
      Attribution. You must give the original author credit.
      Share Alike. If you alter, transform, or build upon this work,
      you may distribute the resulting work only under a license
      identical to this one.
      For any reuse or distribution, you must make clear to oth-
      ers the license terms of this work.
  Any of these conditions can be waived if you get permission from
  the copyright holder.
                              Vittorio Giovara    Misra C Software Development Standard
Outline
                             Introduction
           Reliability Coding Guidelines
                            Applications
                        Further readings



        You can read more about this licence here
http://creativecommons.org/licenses/by-sa/3.0/




       Corrections, suggestions, contributions and
                translations are welcome!

                                Document revision 1.0


                        Vittorio Giovara     Misra C Software Development Standard
Outline
                                Introduction
              Reliability Coding Guidelines
                               Applications
                           Further readings



1   Introduction
       What is MISRA C
       Software Reliability Program
2   Reliability Coding Guidelines
      Overview
      Rules in Practice
      Extract from the guidelines
      Code Examples
3   Applications
      Tools
      Criticsm
4   Further readings

                           Vittorio Giovara    Misra C Software Development Standard
Outline
                                 Introduction
                                                What is MISRA C
               Reliability Coding Guidelines
                                                Software Reliability Program
                                Applications
                            Further readings

MISRA Mission Statement




      To provide assistance to the automotive industry in the
    application and creation within vehicle systems of safe and
                         reliable software.




                            Vittorio Giovara    Misra C Software Development Standard
Outline
                                   Introduction
                                                  What is MISRA C
                 Reliability Coding Guidelines
                                                  Software Reliability Program
                                  Applications
                              Further readings

Association and Purposes


  MISRA C
  It is a software development standard for the C programming
  language. Its aims are to facilitate code portability and reliability
  in the context of embedded systems, specifically those systems
  programmed in ANSI C.

  Standards and reliability
  Even though there is not a MISRA certification process, MISRA
  guidelines are thoroughly followed, expecially in automotive
  industry, as they represent one of the most popular standards
  for developing secure software.


                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                Overview
                                 Introduction
                                                Rules in Practice
               Reliability Coding Guidelines
                                                Extract from the guidelines
                                Applications
                                                Code Examples
                            Further readings

Guidelines main targets


      MISRA has developed a set of coding guidelines for the
      programming language C while other languages (like C++)
      are under discussion.
      The C guidelines are intended to be applied during the
      development of software used in safety-critical
      applications.
      Even if these guidelines are produced for the automotive
      industry, they are often applied to other industries (like
      medical devices).
      Most of the guidelines can be enforced by performing static
      code analysis on application source code.


                            Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings

Versions



  There are two different versions of the MISRA C guidelines
  (while a third is to be released in 2010)
    1   MISRA-C:1998 - Guidelines for the use of the C language
        in vehicle based software - 127 rules (93 compulsory, 34
        advisory)
    2   MISRA-C:2004 - Guidelines for the use of the C language
        in critical systems -141 rulse (121 compulsory, 20
        advisory)




                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                   Overview
                                    Introduction
                                                   Rules in Practice
                  Reliability Coding Guidelines
                                                   Extract from the guidelines
                                   Applications
                                                   Code Examples
                               Further readings

Versions

  Supported standards
  Only ANSI C90 standard is supported, there is no plan for an
  update to the more modern standard C99.

  Why update MISRA C?
  MISRA C was originally developed to support the language
  requirements of the 1994 MISRA Guidelines, that specify the use of
  "a restricted subset of a standardized structured language" at SIL 2
  and above in automotive applications. Since that time, however,
  MISRA C has been adopted and used across a wide variety of
  industries and applications including the rail, aerospace, military and
  medical sectors. Furthermore, a significant number of tools are
  available that support enforcing the MISRA C rules.a
    a
        from the MISRA C2 FAQ
                               Vittorio Giovara    Misra C Software Development Standard
Outline
                                                 Overview
                                  Introduction
                                                 Rules in Practice
                Reliability Coding Guidelines
                                                 Extract from the guidelines
                                 Applications
                                                 Code Examples
                             Further readings

General point



  The guidelines specify that all of the rules apply equally to
  human and machine generated code. Some rules have their
  basis in psychological findings (i.e. how developers read the
  source). Such issues are not important in machine generated
  code (because such code is never read by humans). Those
  rules that are motivated by how humans process source code
  are flagged as such, so that they may be allowed in machine
  generated code.




                             Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings

Rules examples

    5 Use of characters are required to be in the source character set.
      This excludes the characters $ and @, among others.
   22 Declarations of identifiers denoting objects should have the
      narrowest block scope unless a wider scope is necessary.
   34 The operands of the && and || operators shall be enclosed in
      parenthesis unless they are single identifiers.
   67 Identifiers modified within the increment expression of a loop
      header shall not be modified inside the block controlled by that
      loop header.
  103 Relational operators shall not be applied to objects of pointer
      type except where both operands are of the same type and both
      point into the same object.

                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings

Character encoding



  Use of characters are required to be in the source character set. This
  excludes the characters $ and @, among others.


   signed char dollar = ’$’;

   signed char esc_m = ’m’;


  Undefined behaviour for a not defined escape sequence.




                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings

Object Identifiers

  Declarations of identifiers denoting objects should have the narrowest
  block scope unless a wider scope is necessary.

   typedef int MY_INT;
                                                     void MISRA_version_2(void){
   static MY_INT use_me;
                                                     MY_INT local = 3;
   extern MY_INT abuse_me;
                                                     if (ei_1){
   extern func(MY_INT *);
                                                        local+=ei_1;
   extern MY_INT ei_1, ei_2;
                                                        ei_2=local;
                                                        func(&local);
   void f(void){
                                                        ei_1+=local;
          use_me++;
                                                        }
   }
                                                     ei_1=33;
   void g(void){
                                                     }
          abuse_me++;
   }
                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                Overview
                                 Introduction
                                                Rules in Practice
               Reliability Coding Guidelines
                                                Extract from the guidelines
                                Applications
                                                Code Examples
                            Further readings




f() is the only function that references a file scope static. The
definition of use_me could be moved to a file scope static.


g() might be the only function in the translation unit that accesses a
file scope object. But the linkage is external, so functions in other
translation units might access it Define it within the function as an
extern int you say. Nope. This has all sorts of potentially nasty
undefined behaviours (interestingly not covered by the MISRA C
document).


In the codeblock the object local is only accessed within one block.
The definition could be moved to the start of that block; such
movement would be consistent with the intent of this rule in reducing
the visibility of identifiers.


                            Vittorio Giovara    Misra C Software Development Standard
Outline
                                                    Overview
                                     Introduction
                                                    Rules in Practice
                   Reliability Coding Guidelines
                                                    Extract from the guidelines
                                    Applications
                                                    Code Examples
                                Further readings

Logical operators

  The operands of the && and || operators shall be enclosed in
  parenthesis unless they are single identifiers.

  if ((var++) || (num == 11)){...} /* OK */
  if (var++ || num == 11){...} /* NOT OK */

  if ((vect[num]) && (num == 11)){...} /* OK */
  if ((structure.field != 0) && (num < 11)){...} /* OK */
  if (vect[num] == 4 && (num == 11)){...} /* NOT OK */

  Primary-expressions don’t exist, as such, in the preprocessor. If we assume
  the same syntactic forms as semantics expressions we need to know the
  status of the define preprocessor operator. Note that unary operators create
  a unary-expression, while arrays and structure references are
  postfix-expression.

                                Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings

Loop blocks

  Identifiers modified within the increment expression of a loop header
  shall not be modified inside the block controlled by that loop header.

  int flag, si,array[10];
  char *pc;

  flag=1;
  for (si=0; (si<5) && (flag==1); si++){
     flag=0; /* OK, even if it is a loop control variable */
     si=si+3; /* NOT OK, it is involved in the loop variables */
     }

  for (pc=array; pc<array+10; pc++){
     pc++; /* OK, MISRA says numeric, not scalar */
     }

                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                             Overview
                              Introduction
                                             Rules in Practice
            Reliability Coding Guidelines
                                             Extract from the guidelines
                             Applications
                                             Code Examples
                         Further readings




for (si=0; si<ei; si++){
   si++; /* NOT OK */
   ei++; /* NOT OK, it is involved with iteration counting */
   }

flag=0;
for (si=0; flag==0 ; ei++){
   si += 2; /* OK */
   if (si < ei){
      flag = 1; /* OK */
      }
   }

for (array[si]=0; array[si] < 10; array[si]++){
   array[ei]--; /* NOT OK, array[si] has different elements*/
   }


                         Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings

Relational operators


  Relational operators shall not be applied to objects of pointer type
  except where both operands are of the same type and both point into
  the same object.




  Starting conditions:

   extern int *pi_1, *pi_2;
   extern int ai_1[10],ai_2[20];
   extern char *pc;



                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                  Overview
                                   Introduction
                                                  Rules in Practice
                 Reliability Coding Guidelines
                                                  Extract from the guidelines
                                  Applications
                                                  Code Examples
                              Further readings


Not passing code:                                  Passing code:
    if (pi_1 > (int *)pc){                                  if (pi_1 == pi_2){
       si++;                                                   si++;
       }                                                       }
    if (pi_1 == pc){                                        if (pi_1 < pi_1+1){
       si++;                                                   si++;
       }                                                       }
    if (pi_1 >= pc){                                        if (pi_1 >= pc){
       si++;                                                   si++;
       }                                                       }
                                                            if (pi_1 == (int *)pc){
                                                               si++;
                                                               }

The Not passing code is also not C compliant, the C complier should print
warnings.


                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                                Overview
                                 Introduction
                                                Rules in Practice
               Reliability Coding Guidelines
                                                Extract from the guidelines
                                Applications
                                                Code Examples
                            Further readings




Let’s make sure we know what we are pointing at.

pi_1=ai_1+2;
pi_2=ai_1+si;

Not passing code:                                Passing code:
    if (pi_2 > ai_2){                                     if (pi_1 < pi_2){
       si--;                                                 si--;
       }                                                     }
    pi_2=ai_2+si;                                         if (pi_1 != pi_2){
                                                             si--;
    if (pi_1 > pi_2){                                        }
       si++;
       }


                            Vittorio Giovara    Misra C Software Development Standard
Outline
                                    Introduction
                                                   Tools
                  Reliability Coding Guidelines
                                                   Criticsm
                                   Applications
                               Further readings

Static Analyzers


  The Static Analyzers check the code by parsing the source code of
  the program and applying MISRA rules over it. Most of them support
  both version 1998 and 2004 of the MISRA C guidelines.

         QA-C by Programming Research, is a full feartured MISRA C1 and
                C2 validator.

      Testbed by LDRA, offers a static and dynamic analysis.
      PC-Lint by Gimpel, is one of the fastest and least expensive validtors.
         DAC by Ristan-CASE, provides a reverse engineering,
                documentation and code analyzer.




                               Vittorio Giovara    Misra C Software Development Standard
Outline
                                    Introduction
                                                   Tools
                  Reliability Coding Guidelines
                                                   Criticsm
                                   Applications
                               Further readings

Compile Analyzers



  The Compile Analyzers check the code dinamically, while compiling
  the program, and notify MISRA warnings in a separete list from
  normal compilation errors. They are available for many different target
  platforms.
           IAR for multiple platform devices.
           Keil for ARM and 166/7 processors.
    TASKING for Tricore, 166/ST10, 8051, XA and M16C cpus.




                               Vittorio Giovara    Misra C Software Development Standard
Outline
                                   Introduction
                                                  Tools
                 Reliability Coding Guidelines
                                                  Criticsm
                                  Applications
                              Further readings

Some common problems



  Even though MISRA provides a very high quality set of guidelines,
  there are yet some basic problems involved.

      Some technical inaccuracies involving the C language
      Problems with the C Standard clause used as the source of
      coding guidelines.
      Wording of some rules sometimes causes misunderstandings.
      No support for C99 standard or other languages.




                              Vittorio Giovara    Misra C Software Development Standard
Outline
                                Introduction
              Reliability Coding Guidelines
                               Applications
                           Further readings




Please visit as reference
    http://www.misra.org.uk/
    http://www.misra-c2.com/
    http://www.knosof.co.uk/misracom.html
    http://en.wikipedia.org/wiki/MISRA_C

Original document localized at
    http://www.scribd.com/people/view/59403




                           Vittorio Giovara    Misra C Software Development Standard

Contenu connexe

Tendances

MISRA Safety Case Guidelines -
MISRA Safety Case Guidelines - MISRA Safety Case Guidelines -
MISRA Safety Case Guidelines -
Automotive IQ
 

Tendances (20)

Autosar basics by ARCCORE
Autosar basics by ARCCOREAutosar basics by ARCCORE
Autosar basics by ARCCORE
 
PX4 Setup Workshop
PX4 Setup WorkshopPX4 Setup Workshop
PX4 Setup Workshop
 
AUTOSAR_EXP_LayeredSoftwareArchitecture.pdf
AUTOSAR_EXP_LayeredSoftwareArchitecture.pdfAUTOSAR_EXP_LayeredSoftwareArchitecture.pdf
AUTOSAR_EXP_LayeredSoftwareArchitecture.pdf
 
Autosar fundamental
Autosar fundamentalAutosar fundamental
Autosar fundamental
 
Autosar MCAL (Microcontroller Abstraction Layer)
Autosar MCAL (Microcontroller Abstraction Layer)Autosar MCAL (Microcontroller Abstraction Layer)
Autosar MCAL (Microcontroller Abstraction Layer)
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
MISRA Safety Case Guidelines -
MISRA Safety Case Guidelines - MISRA Safety Case Guidelines -
MISRA Safety Case Guidelines -
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Real Time Operating Systems for Embedded Systems
Real Time Operating Systems for Embedded SystemsReal Time Operating Systems for Embedded Systems
Real Time Operating Systems for Embedded Systems
 
Embedded c
Embedded cEmbedded c
Embedded c
 
Model-based Automotive Software Development using Autosar, UML, and Domain-Sp...
Model-based Automotive Software Development using Autosar, UML, and Domain-Sp...Model-based Automotive Software Development using Autosar, UML, and Domain-Sp...
Model-based Automotive Software Development using Autosar, UML, and Domain-Sp...
 
Frequently Asked Questions on AUTOSAR Services
Frequently Asked Questions on AUTOSAR ServicesFrequently Asked Questions on AUTOSAR Services
Frequently Asked Questions on AUTOSAR Services
 
Iso26262 component reuse_webinar
Iso26262 component reuse_webinarIso26262 component reuse_webinar
Iso26262 component reuse_webinar
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
AUToSAR introduction
AUToSAR introductionAUToSAR introduction
AUToSAR introduction
 
What is AUTOSAR MCAL? Learn about the software module architecture and device...
What is AUTOSAR MCAL? Learn about the software module architecture and device...What is AUTOSAR MCAL? Learn about the software module architecture and device...
What is AUTOSAR MCAL? Learn about the software module architecture and device...
 
Automative basics v3
Automative basics v3Automative basics v3
Automative basics v3
 

En vedette

MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016
Andrew Banks
 
Misra c-2004
Misra c-2004Misra c-2004
Misra c-2004
sand390
 
Yazılım kalitesi ve Standartları
Yazılım kalitesi  ve Standartları Yazılım kalitesi  ve Standartları
Yazılım kalitesi ve Standartları
İbrahim ATAY
 
Standard work in software development less 2011 11-01
Standard work in software development less 2011 11-01Standard work in software development less 2011 11-01
Standard work in software development less 2011 11-01
Håkan Forss
 

En vedette (20)

MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016MISRA C Chairman - Device Developer Conference 2016
MISRA C Chairman - Device Developer Conference 2016
 
Misra c-2004
Misra c-2004Misra c-2004
Misra c-2004
 
Software Development by the Genomics Standards Consortium
Software Development by the Genomics  Standards ConsortiumSoftware Development by the Genomics  Standards Consortium
Software Development by the Genomics Standards Consortium
 
Development of Safety Case for the Wolsong LILW disposal facility in Korea
Development of Safety Case for the Wolsong LILW disposal facility in KoreaDevelopment of Safety Case for the Wolsong LILW disposal facility in Korea
Development of Safety Case for the Wolsong LILW disposal facility in Korea
 
.NET Coding Standards For The Real World (2012)
.NET Coding Standards For The Real World (2012).NET Coding Standards For The Real World (2012)
.NET Coding Standards For The Real World (2012)
 
imitrix Software Entwicklung Karlsruhe
imitrix Software Entwicklung Karlsruheimitrix Software Entwicklung Karlsruhe
imitrix Software Entwicklung Karlsruhe
 
Misra cpp, cert cpp 2016 and RTL design style guide with HAZOP
Misra cpp, cert cpp 2016 and RTL design style guide with HAZOPMisra cpp, cert cpp 2016 and RTL design style guide with HAZOP
Misra cpp, cert cpp 2016 and RTL design style guide with HAZOP
 
Multi-Core (MC) Processor Qualification for Safety Critical Systems
Multi-Core (MC) Processor Qualification for Safety Critical SystemsMulti-Core (MC) Processor Qualification for Safety Critical Systems
Multi-Core (MC) Processor Qualification for Safety Critical Systems
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Yazılım kalitesi ve Standartları
Yazılım kalitesi  ve Standartları Yazılım kalitesi  ve Standartları
Yazılım kalitesi ve Standartları
 
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
".NET und jetzt!" C# in 21 Tagen oder doch besser Best Practices
 
HIS Conf 2014: An Insight into MISRA-C
HIS Conf 2014: An Insight into MISRA-CHIS Conf 2014: An Insight into MISRA-C
HIS Conf 2014: An Insight into MISRA-C
 
Standard work in software development less 2011 11-01
Standard work in software development less 2011 11-01Standard work in software development less 2011 11-01
Standard work in software development less 2011 11-01
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCop
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelines
 
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
Basics of Functional Neuroanatomy
Basics of Functional NeuroanatomyBasics of Functional Neuroanatomy
Basics of Functional Neuroanatomy
 
List of Software Development Model and Methods
List of Software Development Model and MethodsList of Software Development Model and Methods
List of Software Development Model and Methods
 

Similaire à Misra C Software Development Standard

“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...
“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...
“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...
Edge AI and Vision Alliance
 
“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...
“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...
“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...
Edge AI and Vision Alliance
 
An end to-end solution for creating smarter products
An end to-end solution for creating smarter productsAn end to-end solution for creating smarter products
An end to-end solution for creating smarter products
IBM Rational software
 
Cloud computing-insights-from-110-implementation-projects
Cloud computing-insights-from-110-implementation-projectsCloud computing-insights-from-110-implementation-projects
Cloud computing-insights-from-110-implementation-projects
Accenture
 

Similaire à Misra C Software Development Standard (20)

Achieving Software Safety, Security, and Reliability Part 2
Achieving Software Safety, Security, and Reliability Part 2Achieving Software Safety, Security, and Reliability Part 2
Achieving Software Safety, Security, and Reliability Part 2
 
fso-landscape
fso-landscape fso-landscape
fso-landscape
 
MISRA-Compliance-2020.pdf
MISRA-Compliance-2020.pdfMISRA-Compliance-2020.pdf
MISRA-Compliance-2020.pdf
 
MISRA-Compliance-2020
MISRA-Compliance-2020MISRA-Compliance-2020
MISRA-Compliance-2020
 
CMAPS_KPIT_Siddharth Mishra.pptx
CMAPS_KPIT_Siddharth Mishra.pptxCMAPS_KPIT_Siddharth Mishra.pptx
CMAPS_KPIT_Siddharth Mishra.pptx
 
“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...
“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...
“IoT and Vision: Why It’s a Security Minefield and How to Navigate It,” a Pre...
 
V&V Lessons Learnt under multiple Standards
V&V Lessons Learnt under multiple StandardsV&V Lessons Learnt under multiple Standards
V&V Lessons Learnt under multiple Standards
 
C Programming and Coding Standards, Learn C Programming
C Programming and Coding Standards, Learn C ProgrammingC Programming and Coding Standards, Learn C Programming
C Programming and Coding Standards, Learn C Programming
 
IRJET- How Artificial Intelligence Accelerates Software Development
IRJET- How Artificial Intelligence Accelerates Software DevelopmentIRJET- How Artificial Intelligence Accelerates Software Development
IRJET- How Artificial Intelligence Accelerates Software Development
 
Webinar misra and security
Webinar   misra and securityWebinar   misra and security
Webinar misra and security
 
DevOps: Age Of CI/CD
DevOps: Age Of CI/CDDevOps: Age Of CI/CD
DevOps: Age Of CI/CD
 
“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...
“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...
“Open Standards Unleash Hardware Acceleration for Embedded Vision,” a Present...
 
Navigating the jungle of Secure Coding Standards
Navigating the jungle of Secure Coding StandardsNavigating the jungle of Secure Coding Standards
Navigating the jungle of Secure Coding Standards
 
Cybersecurity in Automotive Connected Vehicles and Growing Security Vulnerabi...
Cybersecurity in Automotive Connected Vehicles and Growing Security Vulnerabi...Cybersecurity in Automotive Connected Vehicles and Growing Security Vulnerabi...
Cybersecurity in Automotive Connected Vehicles and Growing Security Vulnerabi...
 
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
 
An end to-end solution for creating smarter products
An end to-end solution for creating smarter productsAn end to-end solution for creating smarter products
An end to-end solution for creating smarter products
 
Cloud computing-insights-from-110-implementation-projects
Cloud computing-insights-from-110-implementation-projectsCloud computing-insights-from-110-implementation-projects
Cloud computing-insights-from-110-implementation-projects
 
Cloud Insights from 110 Projects
Cloud Insights from 110 ProjectsCloud Insights from 110 Projects
Cloud Insights from 110 Projects
 
Driving Risks Out of Embedded Automotive Software
Driving Risks Out of Embedded Automotive SoftwareDriving Risks Out of Embedded Automotive Software
Driving Risks Out of Embedded Automotive Software
 
2023 Top Advantage of Web Development Framework.pptx
2023 Top Advantage of Web Development Framework.pptx2023 Top Advantage of Web Development Framework.pptx
2023 Top Advantage of Web Development Framework.pptx
 

Plus de Vittorio Giovara

Plus de Vittorio Giovara (13)

Color me intrigued: A jaunt through color technology in video
Color me intrigued: A jaunt through color technology in videoColor me intrigued: A jaunt through color technology in video
Color me intrigued: A jaunt through color technology in video
 
An overview on 10 bit video: UHDTV, HDR, and coding efficiency
An overview on 10 bit video: UHDTV, HDR, and coding efficiencyAn overview on 10 bit video: UHDTV, HDR, and coding efficiency
An overview on 10 bit video: UHDTV, HDR, and coding efficiency
 
Introduction to video reverse engineering
Introduction to video reverse engineeringIntroduction to video reverse engineering
Introduction to video reverse engineering
 
Il Caso Ryanair
Il Caso RyanairIl Caso Ryanair
Il Caso Ryanair
 
I Mercati Geografici
I Mercati GeograficiI Mercati Geografici
I Mercati Geografici
 
Block Cipher Modes of Operation And Cmac For Authentication
Block Cipher Modes of Operation And Cmac For AuthenticationBlock Cipher Modes of Operation And Cmac For Authentication
Block Cipher Modes of Operation And Cmac For Authentication
 
Crittografia Quantistica
Crittografia QuantisticaCrittografia Quantistica
Crittografia Quantistica
 
Fuzzing Techniques for Software Vulnerability Discovery
Fuzzing Techniques for Software Vulnerability DiscoveryFuzzing Techniques for Software Vulnerability Discovery
Fuzzing Techniques for Software Vulnerability Discovery
 
Parallel and Distributed Computing on Low Latency Clusters
Parallel and Distributed Computing on Low Latency ClustersParallel and Distributed Computing on Low Latency Clusters
Parallel and Distributed Computing on Low Latency Clusters
 
Software Requirements for Safety-related Systems
Software Requirements for Safety-related SystemsSoftware Requirements for Safety-related Systems
Software Requirements for Safety-related Systems
 
Microprocessor-based Systems 48/32bit Division Algorithm
Microprocessor-based Systems 48/32bit Division AlgorithmMicroprocessor-based Systems 48/32bit Division Algorithm
Microprocessor-based Systems 48/32bit Division Algorithm
 
OpenSSL User Manual and Data Format
OpenSSL User Manual and Data FormatOpenSSL User Manual and Data Format
OpenSSL User Manual and Data Format
 
Authenticated Encryption Gcm Ccm
Authenticated Encryption Gcm CcmAuthenticated Encryption Gcm Ccm
Authenticated Encryption Gcm Ccm
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Misra C Software Development Standard

  • 1. Outline Introduction Reliability Coding Guidelines Applications Further readings Misra C Software Development Standard Vittorio Giovara Politecnico di Torino Software Engineering 03/10/2008 Vittorio Giovara Misra C Software Development Standard
  • 2. Outline Introduction Reliability Coding Guidelines Applications Further readings Creative Common Licence v3.0 Attribution - ShareAlike You are free to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions Attribution. You must give the original author credit. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to oth- ers the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Vittorio Giovara Misra C Software Development Standard
  • 3. Outline Introduction Reliability Coding Guidelines Applications Further readings You can read more about this licence here http://creativecommons.org/licenses/by-sa/3.0/ Corrections, suggestions, contributions and translations are welcome! Document revision 1.0 Vittorio Giovara Misra C Software Development Standard
  • 4. Outline Introduction Reliability Coding Guidelines Applications Further readings 1 Introduction What is MISRA C Software Reliability Program 2 Reliability Coding Guidelines Overview Rules in Practice Extract from the guidelines Code Examples 3 Applications Tools Criticsm 4 Further readings Vittorio Giovara Misra C Software Development Standard
  • 5. Outline Introduction What is MISRA C Reliability Coding Guidelines Software Reliability Program Applications Further readings MISRA Mission Statement To provide assistance to the automotive industry in the application and creation within vehicle systems of safe and reliable software. Vittorio Giovara Misra C Software Development Standard
  • 6. Outline Introduction What is MISRA C Reliability Coding Guidelines Software Reliability Program Applications Further readings Association and Purposes MISRA C It is a software development standard for the C programming language. Its aims are to facilitate code portability and reliability in the context of embedded systems, specifically those systems programmed in ANSI C. Standards and reliability Even though there is not a MISRA certification process, MISRA guidelines are thoroughly followed, expecially in automotive industry, as they represent one of the most popular standards for developing secure software. Vittorio Giovara Misra C Software Development Standard
  • 7. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Guidelines main targets MISRA has developed a set of coding guidelines for the programming language C while other languages (like C++) are under discussion. The C guidelines are intended to be applied during the development of software used in safety-critical applications. Even if these guidelines are produced for the automotive industry, they are often applied to other industries (like medical devices). Most of the guidelines can be enforced by performing static code analysis on application source code. Vittorio Giovara Misra C Software Development Standard
  • 8. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Versions There are two different versions of the MISRA C guidelines (while a third is to be released in 2010) 1 MISRA-C:1998 - Guidelines for the use of the C language in vehicle based software - 127 rules (93 compulsory, 34 advisory) 2 MISRA-C:2004 - Guidelines for the use of the C language in critical systems -141 rulse (121 compulsory, 20 advisory) Vittorio Giovara Misra C Software Development Standard
  • 9. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Versions Supported standards Only ANSI C90 standard is supported, there is no plan for an update to the more modern standard C99. Why update MISRA C? MISRA C was originally developed to support the language requirements of the 1994 MISRA Guidelines, that specify the use of "a restricted subset of a standardized structured language" at SIL 2 and above in automotive applications. Since that time, however, MISRA C has been adopted and used across a wide variety of industries and applications including the rail, aerospace, military and medical sectors. Furthermore, a significant number of tools are available that support enforcing the MISRA C rules.a a from the MISRA C2 FAQ Vittorio Giovara Misra C Software Development Standard
  • 10. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings General point The guidelines specify that all of the rules apply equally to human and machine generated code. Some rules have their basis in psychological findings (i.e. how developers read the source). Such issues are not important in machine generated code (because such code is never read by humans). Those rules that are motivated by how humans process source code are flagged as such, so that they may be allowed in machine generated code. Vittorio Giovara Misra C Software Development Standard
  • 11. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Rules examples 5 Use of characters are required to be in the source character set. This excludes the characters $ and @, among others. 22 Declarations of identifiers denoting objects should have the narrowest block scope unless a wider scope is necessary. 34 The operands of the && and || operators shall be enclosed in parenthesis unless they are single identifiers. 67 Identifiers modified within the increment expression of a loop header shall not be modified inside the block controlled by that loop header. 103 Relational operators shall not be applied to objects of pointer type except where both operands are of the same type and both point into the same object. Vittorio Giovara Misra C Software Development Standard
  • 12. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Character encoding Use of characters are required to be in the source character set. This excludes the characters $ and @, among others. signed char dollar = ’$’; signed char esc_m = ’m’; Undefined behaviour for a not defined escape sequence. Vittorio Giovara Misra C Software Development Standard
  • 13. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Object Identifiers Declarations of identifiers denoting objects should have the narrowest block scope unless a wider scope is necessary. typedef int MY_INT; void MISRA_version_2(void){ static MY_INT use_me; MY_INT local = 3; extern MY_INT abuse_me; if (ei_1){ extern func(MY_INT *); local+=ei_1; extern MY_INT ei_1, ei_2; ei_2=local; func(&local); void f(void){ ei_1+=local; use_me++; } } ei_1=33; void g(void){ } abuse_me++; } Vittorio Giovara Misra C Software Development Standard
  • 14. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings f() is the only function that references a file scope static. The definition of use_me could be moved to a file scope static. g() might be the only function in the translation unit that accesses a file scope object. But the linkage is external, so functions in other translation units might access it Define it within the function as an extern int you say. Nope. This has all sorts of potentially nasty undefined behaviours (interestingly not covered by the MISRA C document). In the codeblock the object local is only accessed within one block. The definition could be moved to the start of that block; such movement would be consistent with the intent of this rule in reducing the visibility of identifiers. Vittorio Giovara Misra C Software Development Standard
  • 15. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Logical operators The operands of the && and || operators shall be enclosed in parenthesis unless they are single identifiers. if ((var++) || (num == 11)){...} /* OK */ if (var++ || num == 11){...} /* NOT OK */ if ((vect[num]) && (num == 11)){...} /* OK */ if ((structure.field != 0) && (num < 11)){...} /* OK */ if (vect[num] == 4 && (num == 11)){...} /* NOT OK */ Primary-expressions don’t exist, as such, in the preprocessor. If we assume the same syntactic forms as semantics expressions we need to know the status of the define preprocessor operator. Note that unary operators create a unary-expression, while arrays and structure references are postfix-expression. Vittorio Giovara Misra C Software Development Standard
  • 16. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Loop blocks Identifiers modified within the increment expression of a loop header shall not be modified inside the block controlled by that loop header. int flag, si,array[10]; char *pc; flag=1; for (si=0; (si<5) && (flag==1); si++){ flag=0; /* OK, even if it is a loop control variable */ si=si+3; /* NOT OK, it is involved in the loop variables */ } for (pc=array; pc<array+10; pc++){ pc++; /* OK, MISRA says numeric, not scalar */ } Vittorio Giovara Misra C Software Development Standard
  • 17. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings for (si=0; si<ei; si++){ si++; /* NOT OK */ ei++; /* NOT OK, it is involved with iteration counting */ } flag=0; for (si=0; flag==0 ; ei++){ si += 2; /* OK */ if (si < ei){ flag = 1; /* OK */ } } for (array[si]=0; array[si] < 10; array[si]++){ array[ei]--; /* NOT OK, array[si] has different elements*/ } Vittorio Giovara Misra C Software Development Standard
  • 18. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Relational operators Relational operators shall not be applied to objects of pointer type except where both operands are of the same type and both point into the same object. Starting conditions: extern int *pi_1, *pi_2; extern int ai_1[10],ai_2[20]; extern char *pc; Vittorio Giovara Misra C Software Development Standard
  • 19. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Not passing code: Passing code: if (pi_1 > (int *)pc){ if (pi_1 == pi_2){ si++; si++; } } if (pi_1 == pc){ if (pi_1 < pi_1+1){ si++; si++; } } if (pi_1 >= pc){ if (pi_1 >= pc){ si++; si++; } } if (pi_1 == (int *)pc){ si++; } The Not passing code is also not C compliant, the C complier should print warnings. Vittorio Giovara Misra C Software Development Standard
  • 20. Outline Overview Introduction Rules in Practice Reliability Coding Guidelines Extract from the guidelines Applications Code Examples Further readings Let’s make sure we know what we are pointing at. pi_1=ai_1+2; pi_2=ai_1+si; Not passing code: Passing code: if (pi_2 > ai_2){ if (pi_1 < pi_2){ si--; si--; } } pi_2=ai_2+si; if (pi_1 != pi_2){ si--; if (pi_1 > pi_2){ } si++; } Vittorio Giovara Misra C Software Development Standard
  • 21. Outline Introduction Tools Reliability Coding Guidelines Criticsm Applications Further readings Static Analyzers The Static Analyzers check the code by parsing the source code of the program and applying MISRA rules over it. Most of them support both version 1998 and 2004 of the MISRA C guidelines. QA-C by Programming Research, is a full feartured MISRA C1 and C2 validator. Testbed by LDRA, offers a static and dynamic analysis. PC-Lint by Gimpel, is one of the fastest and least expensive validtors. DAC by Ristan-CASE, provides a reverse engineering, documentation and code analyzer. Vittorio Giovara Misra C Software Development Standard
  • 22. Outline Introduction Tools Reliability Coding Guidelines Criticsm Applications Further readings Compile Analyzers The Compile Analyzers check the code dinamically, while compiling the program, and notify MISRA warnings in a separete list from normal compilation errors. They are available for many different target platforms. IAR for multiple platform devices. Keil for ARM and 166/7 processors. TASKING for Tricore, 166/ST10, 8051, XA and M16C cpus. Vittorio Giovara Misra C Software Development Standard
  • 23. Outline Introduction Tools Reliability Coding Guidelines Criticsm Applications Further readings Some common problems Even though MISRA provides a very high quality set of guidelines, there are yet some basic problems involved. Some technical inaccuracies involving the C language Problems with the C Standard clause used as the source of coding guidelines. Wording of some rules sometimes causes misunderstandings. No support for C99 standard or other languages. Vittorio Giovara Misra C Software Development Standard
  • 24. Outline Introduction Reliability Coding Guidelines Applications Further readings Please visit as reference http://www.misra.org.uk/ http://www.misra-c2.com/ http://www.knosof.co.uk/misracom.html http://en.wikipedia.org/wiki/MISRA_C Original document localized at http://www.scribd.com/people/view/59403 Vittorio Giovara Misra C Software Development Standard