scitools.com

← CodeCheck catalog

MISRA C 2004 is a coding standard you can enforce automatically with CodeCheck, Understand's static-analysis engine — in the GUI, from the command line, or in CI.

MISRA C 2004

The Motor Industry Software Reliability Association (MISRA) guidelines for C published in 2004

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

MISRA, The Motor Industry Software Reliability Association, is a collaboration between vehicle manufacturers, component suppliers and engineering consultancies which seeks to promote best practice in developing safety-related electronic systems in road vehicles and other embedded systems. To this end MISRA publishes documents that provide accessible information for engineers and management, and holds events to permit the exchange of experiences between practitioners.

The first edition of the MISRA C Standard was published in 1998, the second edition was released in 2004 with many substantial changes.

www.misra.org.uk

© MIRA Limited, 2004, 2008.
All RulesAdvisoryRequired
Understand % Coverage75%80%75%
Understand Coverage1071691
Total Rules14220122

Checks

Check IDCheck NameSupportedCategory
MISRA04_1.11.1 All code shall conform to ISO/IEC 9899:1990 "Programming languages — C", amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996NoRequired
MISRA04_1.21.2 No reliance shall be placed on undefined or unspecified behaviourNoRequired
MISRA04_1.31.3 Multiple 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 conformNoRequired
MISRA04_1.41.4 The compiler/linker shall be checked to ensure that 31 character significance and case sensitivity are supported for external identifiersNoRequired
MISRA04_1.51.5 Floating-point implementations should comply with a defined floating-point standardNoAdvisory
MISRA04_2.12.1 Assembly language shall be encapsulated and isolated.YesRequired
MISRA04_2.22.2 C99 / CommentsYesRequired
MISRA04_2.32.3 The character sequence /* shall not be used within a comment.YesRequired
MISRA04_2.42.4 Sections of code should not be "commented out"YesAdvisory
MISRA04_3.13.1 All usage of implementation-defined behaviour shall be documentedNoRequired
MISRA04_3.23.2 The character set and the corresponding encoding shall be documentedNoRequired
MISRA04_3.33.3 The implementation of integer division in the chosen compiler should be determined, documented and taken into accountNoAdvisory
MISRA04_3.43.4 All uses of the #pragma directive shall be documented and explainedNoRequired
MISRA04_3.53.5 The implementation defined behaviour and packing of bitfields shall be documented if being relied uponNoRequired
MISRA04_3.63.6 All libraries used in production code shall be written to comply with the provisions of this document, and shall have been subject to appropriate validationNoRequired
MISRA04_4.14.1 Only those escape sequences that are defined in the ISO C standard shall be usedYesRequired
MISRA04_4.24.2 Trigraphs shall not be usedYesRequired
MISRA04_5.15.1 Long Identifier Name SignificanceYesRequired
MISRA04_5.25.2 Shadowed IdentifiersYesRequired
MISRA04_5.35.3 A typedef name shall be a unique identifier.YesRequired
MISRA04_5.45.4 A tag name shall be a unique identifierYesRequired
MISRA04_5.55.5 No object or function identifier with static storage duration should be reusedYesAdvisory
MISRA04_5.65.6 Identifier Reuse in Multiple C Name SpacesYesAdvisory
MISRA04_5.75.7 Identifier ReuseYesAdvisory
MISRA04_6.16.1 The plain char type shall only be used for the storage and use of character valuesYesRequired
MISRA04_6.26.2 Signed char and unsigned char type shall only be used for the storage and use of numeric valuesYesRequired
MISRA04_6.36.3 Typedefs that indicate size and signedness should be used in place of the basic numerical typesYesAdvisory
MISRA04_6.46.4 Bit fields shall only be defined to be of type unsigned int or signed int.YesRequired
MISRA04_6.56.5 Bit fields of signed type shall be at least 2 bits long.( Fuzzy parser )YesRequired
MISRA04_7.17.1 Octal constants (other than zero) and octal escape sequences shall not be used.YesRequired
MISRA04_8.18.1 Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call.NoRequired
MISRA04_8.28.2 Whenever an object or function is declared or defined, its type shall be explicitly statedYesRequired
MISRA04_8.38.3 For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identicalYesRequired
MISRA04_8.48.4 If objects or functions are declared more than once their types shall be compatible.NoRequired
MISRA04_8.58.5 No definitions of objects or functions in a header fileYesRequired
MISRA04_8.68.6 Functions shall be declared at file scopeYesRequired
MISRA04_8.78.7 Objects shall be local if only accessed from one functionYesRequired
MISRA04_8.88.8 An external object or function shall be declared in one and only one fileYesRequired
MISRA04_8.98.9 An identifier with external linkage shall have exactly one external definitionYesRequired
MISRA04_8.108.10 prefer internal linkage over external whenever possibleYesRequired
MISRA04_8.118.11 Use the static keyword for internal linkageYesRequired
MISRA04_8.128.12 Array Size MissingYesRequired
MISRA04_9.19.1 All automatic variables shall have been assigned a value before being usedNoRequired
MISRA04_9.29.2 Braces shall be used to indicate and match the structure in the non-zero initialisation of arrays and structuresYesRequired
MISRA04_9.39.3 = construct in enumerator list shall only be used on either the first item alone, or all items explicitly.YesRequired
MISRA04_10.110.1 The value of an expression of integer type shall not be implicitly converted to a different underlying type if: it is not a conversion to a wider integer type of the same signedness, or (a) the expression is complex, or (b) the expression is not constant and is a function argument, or (c) the expression is not constant and is a return expression (d)NoRequired
MISRA04_10.210.2 The value of an expression of floating type shall not be implicitly converted to a different type if: it is not a conversion to a wider floating type, or (a) the expression is complex, or (b) the expression is a function argument, or (c) the expression is a return expression (d)NoRequired
MISRA04_10.310.3 The 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 expression.NoRequired
MISRA04_10.410.4 The value of a complex expression of floating type shall only be cast to a floating type that is narrower or of the same size.NoRequired
MISRA04_10.510.5 If the bitwise operators ~ and << are applied to an operand with an underlying type of unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operandYesRequired
MISRA04_10.610.6 A U suffix shall be applied to all constants of unsigned typeYesRequired
MISRA04_11.111.1 Conversions shall not be performed between a pointer to a function and any type other than an integral type.NoRequired
MISRA04_11.211.2 Conversions shall not be performed between a pointer to object and any type other than an integral type, another pointer to object type or a pointer to void.NoRequired
MISRA04_11.311.3 A cast should not be performed between a pointer type and an integral type.NoAdvisory
MISRA04_11.411.4 A cast should not be performed between a pointer to object type and a different pointer to object typeYesAdvisory
MISRA04_11.511.5 A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointerYesRequired
MISRA04_12.112.1 Limited dependence should be placed on C's operator precedence rules in expressionsYesAdvisory
MISRA04_12.212.2 The value of an expression shall be the same under any order of evaluation that the standard permitsYesRequired
MISRA04_12.312.3 The sizeof operator shall not be used on expressions that contain side effectsYesRequired
MISRA04_12.412.4 The right-hand operand of a logical && or || operator shall not contain side effectsYesRequired
MISRA04_12.512.5 The operands of a logical && or || shall be primary-expressionsYesRequired
MISRA04_12.612.6 The operands of logical operators (&&, || and !) should be effectively Boolean. Expressions that are effectively Boolean should not be used as operands to operators other than (&&, ||, !, =, ==, != and ?:)YesAdvisory
MISRA04_12.712.7 Bitwise operators shall not be applied to operands whose underlying type is signedYesRequired
MISRA04_12.812.8 The right-hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left-hand operand.YesRequired
MISRA04_12.912.9 The unary minus operator shall not be applied to an expression whose underlying type is unsignedYesRequired
MISRA04_12.1012.10 The comma operator shall not be usedYesRequired
MISRA04_12.1112.11 Evaluation of constant unsigned integer expressions should not lead to wrap-aroundYesAdvisory
MISRA04_12.1212.12 The underlying bit representations of floating-point values shall not be usedYesRequired
MISRA04_12.1312.13 The increment (++) and decrement (--) operators should not be mixed with other operators in an expressionYesAdvisory
MISRA04_13.113.1 Assignment operators shall not be used in expressions that yield a Boolean value.NoRequired
MISRA04_13.213.2 Tests of a value against zero should be made explicit, unless the operand is effectively Boolean.NoAdvisory
MISRA04_13.313.3 Floating-point expressions shall not be tested for equality or inequalityYesRequired
MISRA04_13.413.4 The controlling expression of a for statement shall not contain any objects of floating typeYesRequired
MISRA04_13.513.5 The three expressions of a for statement shall be concerned only with loop control.NoRequired
MISRA04_13.613.6 Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loopYesRequired
MISRA04_13.713.7 Boolean operations whose results are invariant shall not be permittedNoRequired
MISRA04_14.114.1 There shall be no unreachable codeYesRequired
MISRA04_14.214.2 All non-null statements shall either (a) have at least one side-effect however executed, or (b) cause control flow to change (Partial)YesRequired
MISRA04_14.314.3 Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment provided that the first character following the null statement is a white-space characterYesRequired
MISRA04_14.414.4 The goto statement shall not be usedYesRequired
MISRA04_14.514.5 No Continue StatementsYesRequired
MISRA04_14.614.6 For any iteration statement there shall be at most one break statement used for loop terminationYesRequired
MISRA04_14.714.7 A function shall have a single point of exit at the end of the functionYesRequired
MISRA04_14.814.8 The statement forming the body of a switch, while, do ... while or for statement shall be a compound statementYesRequired
MISRA04_14.914.9 An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statementYesRequired
MISRA04_14.1014.10 All if ... else if constructs shall be terminated with an else clauseYesRequired
MISRA04_1515 The MISRA C switch syntax shall be usedYesRequired
MISRA04_15.115.1 A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statementYesRequired
MISRA04_15.215.2 An unconditional break statement shall terminate every non-empty switch clauseYesRequired
MISRA04_15.315.3 The final clause of a switch statement shall be the default clauseYesRequired
MISRA04_15.415.4 A switch expression shall not represent a value that is effectively BooleanYesRequired
MISRA04_15.515.5 Every switch statement shall have at least one case clauseYesRequired
MISRA04_16.116.1 Functions shall not be defined with variable numbers of arguments.YesRequired
MISRA04_16.216.2 Functions shall not call themselves, either directly or indirectly.YesRequired
MISRA04_16.316.3 All prototype parameters must have an identifier.YesRequired
MISRA04_16.416.4 Inconsistent Parameter NamesYesRequired
MISRA04_16.516.5 Missing ParametersYesRequired
MISRA04_16.616.6 The number of arguments passed to a function shall match the number of parametersYesRequired
MISRA04_16.716.7 A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed objectYesAdvisory
MISRA04_16.816.8 All exit paths from a function with non-void return type shall have an explicit return statement with an expressionYesRequired
MISRA04_16.916.9 A function identifier shall only be used with either a preceding &, or with a parenthesised parameter list, which may be emptyYesRequired
MISRA04_16.1016.10 Functions shall not be defined with variable numbers of argumentsNoRequired
MISRA04_17.117.1 Pointer arithmetic shall only be applied to pointers that address an array or array elementNoRequired
MISRA04_17.217.2 Pointer subtraction shall only be applied to pointers that address elements of the same arrayNoRequired
MISRA04_17.317.3 >, >=, <, <= shall not be applied to objects of pointer type, except where they point to the same arrayYesRequired
MISRA04_17.417.4 Array indexing shall be the only allowed form of pointer arithmeticYesRequired
MISRA04_17.517.5 No more than 2 levels of pointer indirectionYesAdvisory
MISRA04_17.617.6 The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist.YesRequired
MISRA04_18.118.1 All structure or union types shall be complete at the end of a translation unit.NoRequired
MISRA04_18.218.2 An object shall not be assigned to an overlapping objectNoRequired
MISRA04_18.318.3 An area of memory shall not be reused for unrelated purposesNoRequired
MISRA04_18.418.4 UnionsYesRequired
MISRA04_19.119.1 #include statements in a file should only be preceded by other preprocessor directives or commentsYesAdvisory
MISRA04_19.219.2 Non-standard characters should not occur in header file names in #include directivesYesAdvisory
MISRA04_19.319.3 The #include directive shall be followed by either a <filename> or "filename" sequenceYesRequired
MISRA04_19.419.4 C macros shall only expand to a braced initialiser, a constant, a string literal, a parenthesised expression, a type qualifier, a storage class specifier, or a do-while-zero construct.NoRequired
MISRA04_19.519.5 Macros shall not be #define'd or #undef'd within a blockYesRequired
MISRA04_19.619.6 Preprocessor #undefYesRequired
MISRA04_19.719.7 A function should be used in preference to a function-like macroYesAdvisory
MISRA04_19.819.8 A function-like macro shall not be invoked without all of its arguments.NoRequired
MISRA04_19.919.9 Arguments to a function-like macro shall not contain tokens that look like preprocessing directivesYesRequired
MISRA04_19.1019.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 # or ##YesRequired
MISRA04_19.1119.11 All macro identifiers in preprocessor directives shall be defined before use, except in #ifdef and #ifndef preprocessor directives and the defined() operatorNoRequired
MISRA04_19.1219.12 There shall be at most one occurrence of the # or ## operators in a single macro definitionYesRequired
MISRA04_19.1319.12 The # and ## operators should not be usedYesAdvisory
MISRA04_19.1419.14 The defined preprocessor operator shall only be used in one of the two standard formsYesRequired
MISRA04_19.1519.15 Precautions shall be taken in order to prevent the contents of a header file being included twiceYesRequired
MISRA04_19.1619.16 Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessorYesRequired
MISRA04_19.1720.14 All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are relatedYesRequired
MISRA04_20.120.1 Reserved or Standard Library Identifiers as MacrosYesRequired
MISRA04_20.220.2 The names of standard library macros and objects shall not be reusedYesRequired
MISRA04_20.320.3 The validity of values passed to library functions shall be checkedNoRequired
MISRA04_20.420.4 Dynamic Memory AllocationYesRequired
MISRA04_20.520.5 The error indicator "errno" shall not be usedYesRequired
MISRA04_20.620.6 The macro offsetof, in library <stddef.h>, shall not be usedYesRequired
MISRA04_20.720.7 The setjmp macro and the longjmp function shall not be usedYesRequired
MISRA04_20.820.8 The signal handling facilities of <signal.h> shall not be usedYesRequired
MISRA04_20.920.9 Including <stdio.h>YesRequired
MISRA04_20.1020.10 The library functions atof, atoi and atol from library <stdlib.h> shall not be usedYesRequired
MISRA04_20.1120.11 The library functions abort, exit, getenv and system from library <stdlib.h> shall not be usedYesRequired
MISRA04_20.1220.12 The time handling functions of library <time.h> shall not be usedYesRequired
MISRA04_21.121.1 Minimisation of run-time failures shall be ensured by the use of at least one of: (a) static analysis tools/techniques; (b) dynamic analysis tools/techniques; (c) explicit coding of checks to handle run-time faults.YesRequired