001/*-------------------------------------------------------------------------+ 002| | 003| Copyright (c) 2009-2019 CQSE GmbH | 004| | 005+-------------------------------------------------------------------------*/ 006package eu.cqse.check.framework.core.ruleset; 007 008import java.util.function.BiConsumer; 009 010/** 011 * Enumeration of all rules of the Misra C:2012 standard. 012 * 013 * This list has been extracted using a script and manually corrected. 014 */ 015public enum EMisraC2012Rule implements IRulesetRule { 016 MISRA_1_1("1.1", 017 "The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation’s translation limits"), 018 MISRA_1_2("1.2", "Language extensions should not be used"), 019 MISRA_1_3("1.3", "There shall be no occurrence of undefined or critical unspecified behaviour"), 020 MISRA_2_1("2.1", "A project shall not contain unreachable code"), 021 MISRA_2_2("2.2", "There shall be no dead code"), 022 MISRA_2_3("2.3", "A project should not contain unused type declarations"), 023 MISRA_2_4("2.4", "A project should not contain unused tag declarations"), 024 MISRA_2_5("2.5", "A project should not contain unused macro declarations"), 025 MISRA_2_6("2.6", "A function should not contain unused label declarations"), 026 MISRA_2_7("2.7", "There should be no unused parameters in functions"), 027 MISRA_3_1("3.1", "The character sequences /* and // shall not be used within a comment"), 028 MISRA_3_2("3.2", "Line-splicing shall not be used in // comments"), 029 MISRA_4_1("4.1", "Octal and hexadecimal escape sequences shall be terminated"), 030 MISRA_4_2("4.2", "Trigraphs should not be used"), 031 MISRA_5_1("5.1", "External identifiers shall be distinct"), 032 MISRA_5_2("5.2", "Identifiers declared in the same scope and name space shall be distinct"), 033 MISRA_5_3("5.3", 034 "An identifier declared in an inner scope shall not hide an identifier declared in an outer scope"), 035 MISRA_5_4("5.4", "Macro identifiers shall be distinct"), 036 MISRA_5_5("5.5", "Identifiers shall be distinct from macro names"), 037 MISRA_5_6("5.6", "A typedef name shall be a unique identifier"), 038 MISRA_5_7("5.7", "A tag name shall be a unique identifier"), 039 MISRA_5_8("5.8", "Identifiers that define objects or functions with external linkage shall beunique"), 040 MISRA_5_9("5.9", "Identifiers that define objects or functions with internal linkage should be unique"), 041 MISRA_6_1("6.1", "Bit-fields shall only be declared with an appropriate type"), 042 MISRA_6_2("6.2", "Single-bit named bit fields shall not be of a signed type"), 043 MISRA_7_1("7.1", "Octal constants shall not be used"), 044 MISRA_7_2("7.2", 045 "A \"u\" or \"U\" suffix shall be applied to all integer constants that arerepresented in an unsigned type"), 046 MISRA_7_3("7.3", "The lowercase character \"l\" shall not be used in a literal suffix"), 047 MISRA_7_4("7.4", 048 "A string literal shall not be assigned to an object unless the object’s type is \"pointer to const-qualified char\""), 049 MISRA_8_1("8.1", "Types shall be explicitly specified"), 050 MISRA_8_2("8.2", "Function types shall be in prototype form with named parameters"), 051 MISRA_8_3("8.3", "All declarations of an object or function shall use the same names and type qualifiers"), 052 MISRA_8_4("8.4", 053 "A compatible declaration shall be visible when an object or function with external linkage is defined"), 054 MISRA_8_5("8.5", "An external object or function shall be declared once in one and only one file"), 055 MISRA_8_6("8.6", "An identifier with external linkage shall have exactly one external definition"), 056 MISRA_8_7("8.7", 057 "Functions and objects should not be defined with external linkage if they are referenced in only one translation unit"), 058 MISRA_8_8("8.8", 059 "The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage"), 060 MISRA_8_9("8.9", "An object should be defined at block scope if its identifier only appears in a single function"), 061 MISRA_8_10("8.10", "An inline function shall be declared with the static storage class"), 062 MISRA_8_11("8.11", "When an array with external linkage is declared, its size should be explicitly specified"), 063 MISRA_8_12("8.12", 064 "Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique"), 065 MISRA_8_13("8.13", "A pointer should point to a const-qualified type whenever possible"), 066 MISRA_8_14("8.14", "The restrict type qualifier shall not be used"), 067 MISRA_9_1("9.1", "The value of an object with automatic storage duration shall not be read before it has been set"), 068 MISRA_9_2("9.2", "The initializer for an aggregate or union shall be enclosed in braces"), 069 MISRA_9_3("9.3", "Arrays shall not be partially initialized"), 070 MISRA_9_4("9.4", "An element of an object shall not be initialized more than once"), 071 MISRA_9_5("9.5", 072 "Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly"), 073 MISRA_10_1("10.1", "Operands shall not be of an inappropriate essential type"), 074 MISRA_10_2("10.2", 075 "Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations"), 076 MISRA_10_3("10.3", 077 "The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category"), 078 MISRA_10_4("10.4", 079 "Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category"), 080 MISRA_10_5("10.5", "The value of an expression should not be cast to an inappropriate essential type"), 081 MISRA_10_6("10.6", 082 "The value of a composite expression shall not be assigned to an object with wider essential type"), 083 MISRA_10_7("10.7", 084 "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"), 085 MISRA_10_8("10.8", 086 "The value of a composite expression shall not be cast to a different essential type category or a wider essential type"), 087 MISRA_11_1("11.1", "Conversions shall not be performed between a pointer to a function and any other type"), 088 MISRA_11_2("11.2", "Conversions shall not be performed between a pointer to an incomplete type and any other type"), 089 MISRA_11_3("11.3", 090 "A cast shall not be performed between a pointer to object type and a pointer to a different object type"), 091 MISRA_11_4("11.4", "A conversion should not be performed between a pointer to object and an integer type"), 092 MISRA_11_5("11.5", "A conversion should not be performed from pointer to void into pointer to object"), 093 MISRA_11_6("11.6", "A cast shall not be performed between pointer to void and an arithmetic type"), 094 MISRA_11_7("11.7", "A cast shall not be performed between pointer to object and a noninteger arithmetic type"), 095 MISRA_11_8("11.8", 096 "A cast shall not remove any const or volatile qualification from the type pointed to by a pointer"), 097 MISRA_11_9("11.9", "The macro NULL shall be the only permitted form of integer null pointer constant"), 098 MISRA_12_1("12.1", "The precedence of operators within expressions should be made explicit"), 099 MISRA_12_2("12.2", 100 "The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand"), 101 MISRA_12_3("12.3", "The comma operator should not be used"), 102 MISRA_12_4("12.4", "Evaluation of constant expressions should not lead to unsigned integer wrap-around"), 103 MISRA_13_1("13.1", "Initializer lists shall not contain persistent side effects"), 104 MISRA_13_2("13.2", 105 "The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders"), 106 MISRA_13_3("13.3", 107 "A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator"), 108 MISRA_13_4("13.4", "The result of an assignment operator should not be used"), 109 MISRA_13_5("13.5", 110 "The right hand operand of a logical && or || operator shall not contain persistent side effects"), 111 MISRA_13_6("13.6", 112 "The operand of the sizeof operator shall not contain any expression which has potential side effects"), 113 MISRA_14_1("14.1", "A loop counter shall not have essentially floating type"), 114 MISRA_14_2("14.2", "A for loop shall be well-formed"), 115 MISRA_14_3("14.3", "Controlling expressions shall not be invariant"), 116 MISRA_14_4("14.4", 117 "The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type"), 118 MISRA_15_1("15.1", "The goto statement should not be used"), 119 MISRA_15_2("15.2", "The goto statement shall jump to a label declared later in the same function"), 120 MISRA_15_3("15.3", 121 "Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement"), 122 MISRA_15_4("15.4", 123 "There should be no more than one break or goto statement used to terminate any iteration statement"), 124 MISRA_15_5("15.5", "A function should have a single point of exit at the end"), 125 MISRA_15_6("15.6", "The body of an iteration-statement or a selection-statement shall be a compound-statement"), 126 MISRA_15_7("15.7", "All if … else if constructs shall be terminated with an else statement"), 127 MISRA_16_1("16.1", "All switch statements shall be well-formed"), 128 MISRA_16_2("16.2", 129 "A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement"), 130 MISRA_16_3("16.3", "An unconditional break statement shall terminate every switch-clause"), 131 MISRA_16_4("16.4", "Every switch statement shall have a default label"), 132 MISRA_16_5("16.5", 133 "A default label shall appear as either the first or the last switch label of a switch statement"), 134 MISRA_16_6("16.6", "Every switch statement shall have at least two switch-clauses"), 135 MISRA_16_7("16.7", "A switch-expression shall not have essentially Boolean type"), 136 MISRA_17_1("17.1", "The features of <stdarg.h> shall not be used"), 137 MISRA_17_2("17.2", "Functions shall not call themselves, either directly or indirectly"), 138 MISRA_17_3("17.3", "A function shall not be declared implicitly"), 139 MISRA_17_4("17.4", 140 "All exit paths from a function with non-void return type shall have an explicit return statement with an expression"), 141 MISRA_17_5("17.5", 142 "The function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elements"), 143 MISRA_17_6("17.6", "The declaration of an array parameter shall not contain the static keyword between the [ ]"), 144 MISRA_17_7("17.7", "The value returned by a function having non-void return type shall beused"), 145 MISRA_17_8("17.8", "A function parameter should not be modified"), 146 MISRA_18_1("18.1", 147 "A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand"), 148 MISRA_18_2("18.2", 149 "Subtraction between pointers shall only be applied to pointers that address elements of the same array"), 150 MISRA_18_3("18.3", 151 "The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object"), 152 MISRA_18_4("18.4", "The +, -, += and -= operators should not be applied to an expression of pointer type"), 153 MISRA_18_5("18.5", "Declarations should contain no more than two levels of pointer nesting"), 154 MISRA_18_6("18.6", 155 "The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist"), 156 MISRA_18_7("18.7", "Flexible array members shall not be declared"), 157 MISRA_18_8("18.8", "Variable-length array types shall not be used"), 158 MISRA_19_1("19.1", "An object shall not be assigned or copied to an overlapping object"), 159 MISRA_19_2("19.2", "The union keyword should not be used"), 160 MISRA_20_1("20.1", "#include directives should only be preceded by preprocessor directives or comments"), 161 MISRA_20_2("20.2", 162 "The ', \" or \\ characters and the /* or // character sequences shall not occur in a header file name"), 163 MISRA_20_3("20.3", "The #include directive shall be followed by either a <filename> or \"filename\" sequence"), 164 MISRA_20_4("20.4", "A macro shall not be defined with the same name as a keyword"), 165 MISRA_20_5("20.5", "#undef should not be used"), 166 MISRA_20_6("20.6", "Tokens that look like a preprocessing directive shall not occur within a macro argument"), 167 MISRA_20_7("20.7", "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses"), 168 MISRA_20_8("20.8", "The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1"), 169 MISRA_20_9("20.9", 170 "All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define’d before evaluation"), 171 MISRA_20_10("20.10", "The # and ## preprocessor operators should not be used"), 172 MISRA_20_11("20.11", 173 "A macro parameter immediately following a # operator shall not immediately be followed by a ## operator"), 174 MISRA_20_12("20.12", 175 "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as anoperand to these operators"), 176 MISRA_20_13("20.13", "A line whose first token is # shall be a valid preprocessing directive"), 177 MISRA_20_14("20.14", 178 "All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related"), 179 MISRA_21_1("21.1", 180 "All resources obtained dynamically by means of Standard Library functions shall be explicitly released"), 181 MISRA_21_2("21.2", "A reserved identifier or macro name shall not be declared"), 182 MISRA_21_3("21.3", "The memory allocation and deallocation functions of <stdlib.h> shall not be used"), 183 MISRA_21_4("21.4", "The standard header file <setjmp.h> shall not be used"), 184 MISRA_21_5("21.5", "The standard header file <signal.h> shall not be used"), 185 MISRA_21_6("21.6", "The Standard Library input/output functions shall not be used"), 186 MISRA_21_7("21.7", "The atof, atoi, atol and atoll functions of <stdlib.h> shall not be used"), 187 MISRA_21_8("21.8", "The library functions abort, exit, getenv and system of <stdlib.h> shall not be used"), 188 MISRA_21_9("21.9", "The library functions bsearch and qsort of <stdlib.h> shall not beused"), 189 MISRA_21_10("21.10", "The Standard Library time and date functions shall not be used"), 190 MISRA_21_11("21.11", "The standard header file <tgmath.h> shall not be used"), 191 MISRA_21_12("21.12", "The exception handling features of <fenv.h> should not be used"), 192 MISRA_22_1("22.1", 193 "All resources obtained dynamically by means of Standard Library functions shall be explicitly released"), 194 MISRA_22_2("22.2", 195 "A block of memory shall only be freed if it was allocated by means of a Standard Library function"), 196 MISRA_22_3("22.3", 197 "The same file shall not be open for read and write access at the same time on different streams"), 198 MISRA_22_4("22.4", "There shall be no attempt to write to a stream which has been opened as read-only"), 199 MISRA_22_5("22.5", "A pointer to a FILE object shall not be dereferenced"), 200 MISRA_22_6("22.6", 201 "The value of a pointer to a FILE shall not be used after the associated stream has been closed"); 202 203 private final String id; 204 205 private final String text; 206 207 EMisraC2012Rule(String id, String name) { 208 this.id = id; 209 this.text = name; 210 } 211 212 @Override 213 public String getRuleId() { 214 return id; 215 } 216 217 @Override 218 public String getRuleText() { 219 return text; 220 } 221 222 @Override 223 public void contributeRules(BiConsumer<String, String> contributor) { 224 // empty 225 } 226}