Transcription of Coverity Support for MISRA Coding Standards
1 | | 1 Fully ensure the safety, reliability, and security of software written in C and C++OverviewSoftware is eating the world. Industries that have traditionally relied on mechanical, electronic, and analog control systems are increasingly replacing them with software-driven systems. For example, the average car is expected to contain 300 million lines of code in the next decade up from 100 million lines of code today. But with the growth of software comes the growth of software defects which can manifest themselves in these systems with tangible and life-threatening consequences.
2 More importantly, malicious actors can deliberately trigger failures for their own complex industries involve many vendors and suppliers simultaneously contributing to the software that goes into the final product. Every participant in this software supply chain must reach consensus on Coding Standards , defect reporting structures, and so on. The confluence of these two factors increasing complexity in software systems and longer software supply chains creates the demand for new MISRA C and C++ Coding Standards are widely used in safety-critical industries, such as automotive, medical, military, and aerospace.
3 The Standards provide a set of best practices for writing C and C++ code, facilitating the authorship of safe, secure, and portable code. With Coverity static analysis, Synopsys provides a comprehensive solution for MISRA standard compliance that is scalable from individual developers all the way to complex software supply chains. Coverity Support for MISRA Coding Standards | | 2 MISRA C:2004 supported rulesRuleRule nameCategorySupportedNotesRule code shall conform to ISO/IEC 9899:1990 Programming languages C , amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1.
4 1995, and ISO/IEC 9899/COR2 reliance shall be placed on undefined or unspecified compilers and/or languages shall only be used if there is a common defined interface standard for object code to which the languages/compilers/assemblers rule is not statically compiler/linker shall be checked to ensure that 31 character significance and case sensitivity are supported for external rule is not statically implementations should comply with a defined floating-point rule is not statically language shall be encapsulated and code shall only use /* .. */ style character sequence /* shall not be used within a of code should not be commented out.
5 AdvisoryYesRule usage of implementation-defined behaviour shall be rule is not statically character set and the corresponding encoding shall be rule is not statically implementation of integer division in the chosen compiler should be determined, documented and taken into rule is not statically uses of the #pragma directive shall be documented and rule is not statically it is being relied upon, the implementation defined behaviour and packing of bitfields shall be rule is not statically libraries used in production code shall be written to comply with the provisions of this document, and shall have been subject to appropriate rule is not statically those escape sequences that are defined in the ISO C standard shall be shall not be C:2004 rule coverageSupportedAllPercent C:2004 The MISRA C:2004 Coding standard supports the C90 language specification.
6 It was first released in 2004 and consists of 142 rules: 124 required and 18 advisory. Coverity covers the entire MISRA C:2004 standard.** All rules that can be checked by static analysis are supported. MISRA C:2004 contains 12 rules that are not statically checkable, so a total of 130 are implemented (out of 142). | | 3 RuleRule nameCategorySupportedNotesRule (internal and external) shall not rely on the significance of more than 31 in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that typedef name shall be a unique tag name shall be a unique object or function identifier with static storage duration should be identifier in one name space should have the same spelling as an identifier in another name space.
7 With the exception of structure member and union member identifier name should be plain char type shall be used only for the storage and use of character and unsigned char type shall be used only for the storage and use of numeric that indicate size and signedness should be used in place of the basic numerical fields shall only be defined to be of type unsigned int or signed fields of signed type shall be at least 2 bits constants (other than zero) and octal escape sequences shall not be shall have prototype declarations and the prototype shall be visible at both the function definition and an object or function is declared or defined, its type shall be explicitly each function parameter the type given in the declaration and definition shall be identical.
8 And the return types shall also be objects or functions are declared more than once their types shall be shall be no definitions of objects or functions in a header shall be declared at file shall be defined at block scope if they are only accessed from within a single external object or function shall be declared in one and only one identifier with external linkage shall have exactly one external declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is static storage class specifier shall be used in definitions and declarations of objects and functions that have internal an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by automatic variables shall have been assigned a value before being | | 4 RuleRule nameCategorySupportedNotesRule shall be used to indicate and match the structure in the non-zero initialisation of arrays and an enumerator list, the = construct shall not be used to explicitly initialise members other than the first.
9 Unless all items are explicitly value of an expression of integer type shall not be implicitly converted to a different underlying type if: (a) it is not a conversion to a wider integer type of the same signedness, or (b) signedness, or the expression is complex, or (c) the expression is not constant and is a function argument, or (d) the expression is not constant and is a return value of an expression of floating type shall not be implicitly converted to a different type if: (a) it is not a conversion to a wider floating type, or (b) the expression is complex, or (c) the expression is a function argument, or (d)
10 The expression is a return value of a complex expression of integer type shall only be cast to a type of the same signedness that is no wider than the underlying type of the value of a complex expression of floating type shall only be cast to a floating type that is narrower or of the same the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the U suffix shall be applied to all constants of unsigned shall not be performed between a pointer to a function and any type other than an integral shall not be performed between a pointer to object and any type other than an integral type.