In the initial compilation phase of the analysis, Polyspace® checks those coding rules that do not require the run-time error detection part of the analysis. If you want only those rules checked, you can perform a much quicker analysis.
The software provides two predefined subsets of rules that it checks earlier in the analysis.
The subsets are available with the options Check MISRA C:2004
(-misra2), Check MISRA AC AGC
(-misra-ac-agc), and Check MISRA C:2012
(-misra3).
| Argument | Purpose |
|---|---|
single-unit-rules | Check rules that apply only to single translation units. If you detect only coding rule violations and select this subset, a Bug Finder analysis stops after the compilation phase. |
system-decidable-rules | Check rules in the If you detect only coding rule violations and select this subset, a Bug Finder analysis stops after the linking phase. |
See also Check for Coding Rule Violations.
The software checks the following rules early in the analysis.
The rules that are checked at a system level and appear only in the system-decidable-rules subset
are indicated by an asterisk.
Environment
| Rule | Description |
|---|---|
| 1.1* | All code shall conform to ISO® 9899:1990 "Programming languages - C", amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996. |
Language Extensions
| Rule | Description |
|---|---|
| 2.1 | Assembly language shall be encapsulated and isolated. |
| 2.2 | Source code shall only use |
| 2.3 | The character sequence |
Documentation
| Rule | Description |
|---|---|
| 3.4 | All uses of the |
Character Sets
| Rule | Description |
|---|---|
| 4.1 | Only those escape sequences which are defined in the ISO C standard shall be used. |
| 4.2 | Trigraphs shall not be used. |
Identifiers
| Rule | Description |
|---|---|
| 5.1* | Identifiers (internal and external) shall not rely on the significance of more than 31 characters. |
| 5.2 | Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier. |
| 5.3* | A typedef name shall be a unique identifier. |
| 5.4* | A tag name shall be a unique identifier. |
| 5.5* | No object or function identifier with a static storage duration should be reused. |
| 5.6* | No identifier in one name space should have the same spelling as an identifier in another name space, with the exception of structure and union member names. |
| 5.7* | No identifier name should be reused. |
Types
| Rule | Description |
|---|---|
| 6.1 | The plain char type shall be used only for the storage and use of character values. |
| 6.2 | Signed and unsigned char type shall be used only for the storage and use of numeric values. |
| 6.3 |
|
| 6.4 | Bit fields shall only be defined to be of type |
| 6.5 | Bit fields of type |
Constants
| Rule | Description |
|---|---|
| 7.1 | Octal constants (other than zero) and octal escape sequences shall not be used. |
Declarations and Definitions
| Rule | Description |
|---|---|
| 8.1 | Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call. |
| 8.2 | Whenever an object or function is declared or defined, its type shall be explicitly stated. |
| 8.3 | For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identical. |
| 8.4* | If objects or functions are declared more than once their types shall be compatible. |
| 8.5 | There shall be no definitions of objects or functions in a header file. |
| 8.6 | Functions shall always be declared at file scope. |
| 8.7 | Objects shall be defined at block scope if they are only accessed from within a single function. |
| 8.8* | An external object or function shall be declared in one file and only one file. |
| 8.9* | An identifier with external linkage shall have exactly one external definition. |
| 8.10* | All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required. |
| 8.11 | The |
| 8.12 | When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization. |
Initialization
| Rule | Description |
|---|---|
| 9.2 | Braces shall be used to indicate and match the structure in the nonzero initialization of arrays and structures. |
| 9.3 | In an enumerator list, the |
Arithmetic Type Conversion
| Rule | Description |
|---|---|
| 10.1 | The value of an expression of integer type shall not be implicitly converted to a different underlying type if:
|
| 10.2 | The value of an expression of floating type shall not be implicitly converted to a different type if
|
| 10.3 | The value of a complex expression of integer type may only be cast to a type that is narrower and of the same signedness as the underlying type of the expression. |
| 10.4 | The value of a complex expression of float type may only be cast to narrower floating type. |
| 10.5 | If the bitwise operator |
| 10.6 | The "U" suffix shall be applied to all constants of |
Pointer Type Conversion
| Rule | Description |
|---|---|
| 11.1 | Conversion shall not be performed between a pointer to a function and any type other than an integral type. |
| 11.2 | Conversion shall not be performed between a pointer to
an object and any type other than an integral type, another pointer
to a object type or a pointer to |
| 11.3 | A cast should not be performed between a pointer type and an integral type. |
| 11.4 | A cast should not be performed between a pointer to object type and a different pointer to object type. |
| 11.5 | A cast shall not be performed that removes any |
Expressions
| Rule | Description |
|---|---|
| 12.1 | Limited dependence should be placed on C's operator precedence rules in expressions. |
| 12.3 | The |
| 12.5 | The operands of a logical |
| 12.6 | Operands of logical operators ( |
| 12.7 | Bitwise operators shall not be applied to operands whose underlying type is signed. |
| 12.9 | The unary minus operator shall not be applied to an expression whose underlying type is unsigned. |
| 12.10 | The comma operator shall not be used. |
| 12.11 | Evaluation of constant unsigned expression should not lead to wraparound. |
| 12.12 | The underlying bit representations of floating-point values shall not be used. |
| 12.13 | The increment ( |
Control Statement Expressions
| Rule | Description |
|---|---|
| 13.1 | Assignment operators shall not be used in expressions that yield Boolean values. |
| 13.2 | Tests of a value against zero should be made explicit, unless the operand is effectively Boolean. |
| 13.3 | Floating-point expressions shall not be tested for equality or inequality. |
| 13.4 | The controlling expression of a |
| 13.5 | The three expressions of a |
| 13.6 | Numeric variables being used within a |
Control Flow
| Rule | Description |
|---|---|
| 14.3 | All non-null statements shall either
|
| 14.4 | The |
| 14.5 | The |
| 14.6 | For any iteration statement, there shall be at most one |
| 14.7 | A function shall have a single point of exit at the end of the function. |
| 14.8 | The statement forming the body of a |
| 14.9 | An |
| 14.10 | All |
Switch Statements
| Rule | Description |
|---|---|
| 15.0 | Unreachable code is detected between |
| 15.1 | A |
| 15.2 | An unconditional |
| 15.3 | The final clause of a |
| 15.4 | A |
| 15.5 | Every |
Functions
| Rule | Description |
|---|---|
| 16.1 | Functions shall not be defined with variable numbers of arguments. |
| 16.3 | Identifiers shall be given for all of the parameters in a function prototype declaration. |
| 16.4* | The identifiers used in the declaration and definition of a function shall be identical. |
| 16.5 | Functions with no parameters shall be declared with parameter
type |
| 16.6 | The number of arguments passed to a function shall match the number of parameters. |
| 16.8 | All exit paths from a function with non- |
| 16.9 | A function identifier shall only be used with either
a preceding |
Pointers and Arrays
| Rule | Description |
|---|---|
| 17.4 | Array indexing shall be the only allowed form of pointer arithmetic. |
| 17.5 | A type should not contain more than 2 levels of pointer indirection. |
Structures and Unions
| Rule | Description |
|---|---|
| 18.1 | All structure or union types shall be complete at the end of a translation unit. |
| 18.4 | Unions shall not be used. |
Preprocessing Directives
| Rule | Description |
|---|---|
| 19.1 |
|
| 19.2 | Nonstandard characters should not occur in header file
names in |
| 19.3 | The |
| 19.4 | C macros shall only expand to a braced initializer, a constant, a parenthesized expression, a type qualifier, a storage class specifier, or a do-while-zero construct. |
| 19.5 | Macros shall not be |
| 19.6 |
|
| 19.7 | A function should be used in preference to a function like-macro. |
| 19.8 | A function-like macro shall not be invoked without all of its arguments. |
| 19.9 | Arguments to a function-like macro shall not contain tokens that look like preprocessing directives. |
| 19.10 | In the definition of a function-like macro, each instance
of a parameter shall be enclosed in parentheses unless it is used
as the operand of |
| 19.11 | All macro identifiers in preprocessor directives shall
be defined before use, except in |
| 19.12 | There shall be at most one occurrence of the |
| 19.13 | The |
| 19.14 | The defined preprocessor operator shall only be used in one of the two standard forms. |
| 19.15 | Precautions shall be taken in order to prevent the contents of a header file being included twice. |
| 19.16 | Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessor. |
| 19.17 | All |
Standard Libraries
| Rule | Description |
|---|---|
| 20.1 | Reserved identifiers, macros and functions in the standard library, shall not be defined, redefined or undefined. |
| 20.2 | The names of standard library macros, objects and functions shall not be reused. |
| 20.4 | Dynamic heap memory allocation shall not be used. |
| 20.5 | The error indicator |
| 20.6 | The macro |
| 20.7 | The |
| 20.8 | The signal handling facilities of |
| 20.9 | The input/output library |
| 20.10 | The library functions |
| 20.11 | The library functions |
| 20.12 | The time handling functions of library |
The rules that are checked at a system level and appear only
in the system-decidable-rules subset are indicated
by an asterisk.
The software checks the following rules early in the analysis.
The rules that are checked at a system level and appear only in the system-decidable-rules subset
are indicated by an asterisk.
Standard C Environment
| Rule | Description |
|---|---|
| 1.1 | The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits. |
| 1.2 | Language extensions should not be used. |
Unused Code
| Rule | Description |
|---|---|
| 2.3* | A project should not contain unused type declarations. |
| 2.4* | A project should not contain unused tag declarations. |
| 2.5* | A project should not contain unused macro declarations. |
| 2.6 | A function should not contain unused label declarations. |
| 2.7 | There should be no unused parameters in functions. |
Comments
| Rule | Description |
|---|---|
| 3.1 | The character sequences |
| 3.2 | Line-splicing shall not be used in |
Character Sets and Lexical Conventions
| Rule | Description |
|---|---|
| 4.1 | Octal and hexadecimal escape sequences shall be terminated. |
| 4.2 | Trigraphs should not be used. |
Identifiers
| Rule | Description |
|---|---|
| 5.1* | External identifiers shall be distinct. |
| 5.2 | Identifiers declared in the same scope and name space shall be distinct. |
| 5.3 | An identifier declared in an inner scope shall not hide an identifier declared in an outer scope. |
| 5.4 | Macro identifiers shall be distinct. |
| 5.5 | Identifiers shall be distinct from macro names. |
| 5.6* | A typedef name shall be a unique identifier. |
| 5.7* | A tag name shall be a unique identifier. |
| 5.8* | Identifiers that define objects or functions with external linkage shall be unique. |
| 5.9* | Identifiers that define objects or functions with internal linkage should be unique. |
Types
| Rule | Description |
|---|---|
| 6.1 | Bit-fields shall only be declared with an appropriate type. |
| 6.2 | Single-bit named bit fields shall not be of a signed type. |
Literals and Constants
| Rule | Description |
|---|---|
| 7.1 | Octal constants shall not be used. |
| 7.2 | A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type. |
| 7.3 | The lowercase character "l" shall not be used in a literal suffix. |
| 7.4 | A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char". |
Declarations and Definitions
| Rule | Description |
|---|---|
| 8.1 | Types shall be explicitly specified. |
| 8.2 | Function types shall be in prototype form with named parameters. |
| 8.3* | All declarations of an object or function shall use the same names and type qualifiers. |
| 8.4 | A compatible declaration shall be visible when an object or function with external linkage is defined. |
| 8.5* | An external object or function shall be declared once in one and only one file. |
| 8.6* | An identifier with external linkage shall have exactly one external definition. |
| 8.7* | Functions and objects should not be defined with external linkage if they are referenced in only one translation unit. |
| 8.8 | The |
| 8.9* | An object should be defined at block scope if its identifier only appears in a single function. |
| 8.10 | An inline function shall be declared with the |
| 8.11 | When an array with external linkage is declared, its size should be explicitly specified. |
| 8.12 | Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique. |
| 8.14 | The |
Initialization
| Rule | Description |
|---|---|
| 9.2 | The initializer for an aggregate or union shall be enclosed in braces. |
| 9.3 | Arrays shall not be partially initialized. |
| 9.4 | An element of an object shall not be initialized more than once. |
| 9.5 | Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly. |
The Essential Type Model
| Rule | Description |
|---|---|
| 10.1 | Operands shall not be of an inappropriate essential type. |
| 10.2 | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations. |
| 10.3 | The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category. |
| 10.4 | Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category. |
| 10.5 | The value of an expression should not be cast to an inappropriate essential type. |
| 10.6 | The value of a composite expression shall not be assigned to an object with wider essential type. |
| 10.7 | If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type. |
| 10.8 | The value of a composite expression shall not be cast to a different essential type category or a wider essential type. |
Pointer Type Conversion
| Rule | Description |
|---|---|
| 11.1 | Conversions shall not be performed between a pointer to a function and any other type. |
| 11.2 | Conversions shall not be performed between a pointer to an incomplete type and any other type. |
| 11.3 | A cast shall not be performed between a pointer to object type and a pointer to a different object type. |
| 11.4 | A conversion should not be performed between a pointer to object and an integer type. |
| 11.5 | A conversion should not be performed from pointer to void into pointer to object. |
| 11.6 | A cast shall not be performed between pointer to void and an arithmetic type. |
| 11.7 | A cast shall not be performed between pointer to object and a non-integer arithmetic type. |
| 11.8 | A cast shall not remove any const or volatile qualification from the type pointed to by a pointer. |
| 11.9 | The macro |
Expressions
| Rule | Description |
|---|---|
| 12.1 | The precedence of operators within expressions should be made explicit. |
| 12.3 | The comma operator should not be used. |
| 12.4 | Evaluation of constant expressions should not lead to unsigned integer wrap-around. |
Side Effects
| Rule | Description |
|---|---|
| 13.3 | A full expression containing an increment ( |
| 13.4 | The result of an assignment operator should not be used. |
| 13.6 | The operand of the |
Control Statement Expressions
| Rule | Description |
|---|---|
| 14.4 | The controlling expression of an |
Control Flow
| Rule | Description |
|---|---|
| 15.1 | The |
| 15.2 | The |
| 15.3 | Any label referenced by a |
| 15.4 | There should be no more than one |
| 15.5 | A function should have a single point of exit at the end |
| 15.6 | The body of an iteration-statement or a selection-statement shall be a compound statement. |
| 15.7 | All |
Switch Statements
| Rule | Description |
|---|---|
| 16.1 | All |
| 16.2 | A |
| 16.3 | An unconditional |
| 16.4 | Every |
| 16.5 | A |
| 16.6 | Every |
| 16.7 | A |
Functions
| Rule | Description |
|---|---|
| 17.1 | The features of |
| 17.3 | A function shall not be declared implicitly. |
| 17.4 | All exit paths from a function with non- |
| 17.6 | The declaration of an array parameter shall not contain
the |
| 17.7 | The value returned by a function having non- |
Pointers and Arrays
| Rule | Description |
|---|---|
| 18.4 | The |
| 18.5 | Declarations should contain no more than two levels of pointer nesting. |
| 18.7 | Flexible array members shall not be declared. |
| 18.8 | Variable-length array types shall not be used. |
Overlapping Storage
| Rule | Description |
|---|---|
| 19.2 | The |
Preprocessing Directives
| Rule | Description |
|---|---|
| 20.1 |
|
| 20.2 | The |
| 20.3 | The |
| 20.4 | A macro shall not be defined with the same name as a keyword. |
| 20.5 |
|
| 20.6 | Tokens that look like a preprocessing directive shall not occur within a macro argument. |
| 20.7 | Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses. |
| 20.8 | The controlling expression of a |
| 20.9 | All identifiers used in the controlling expression of |
| 20.10 | The |
| 20.11 | A macro parameter immediately following a |
| 20.12 | A macro parameter used as an operand to the |
| 20.13 | A line whose first token is |
| 20.14 | All |
Standard Libraries
| Rule | Description |
|---|---|
| 21.1 |
|
| 21.2 | A reserved identifier or macro name shall not be declared. |
| 21.3 | The memory allocation and deallocation functions of |
| 21.4 | The standard header file |
| 21.5 | The standard header file |
| 21.6 | The Standard Library input/output functions shall not be used. |
| 21.7 | The |
| 21.8 | The library functions |
| 21.9 | The library functions |
| 21.10 | The Standard Library time and date functions shall not be used. |
| 21.11 | The standard header file |
| 21.12 | The exception handling features of |
The rules that are checked at a system level and appear only in the
system-decidable-rules subset are indicated by an
asterisk.
Check MISRA AC AGC
(-misra-ac-agc) | Check MISRA
C:2004 (-misra2) | Check MISRA
C:2012 (-misra3)