text
stringlengths
110
791
<s>[INST] find the error in this code: int main() { int x = 5; while (x > 0) {} /* Violation of Rule 14.3 */ x--; return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.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 character.
<s>[INST] find the error in this code: int main() { int x = 5; goto end; // Violation of Rule 14.4 end: return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.4 - The goto statement shall not be used.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { goto end; // Violation of Rule 14.4 } end: return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.4 - The goto statement shall not be used.
<s>[INST] find the error in this code: int main() { int i; for (i = 0; i < 10; ++i) { if (i % 2 == 0) { continue; // Violation of Rule 14.5 } printf("%d\n", i); } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.5 - The continue statement shall not be used.
<s>[INST] find the error in this code: int main() { int i; while (i < 10) { ++i; if (i % 2 == 0) { continue; // Violation of Rule 14.5 } printf("%d\n", i); } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.5 - The continue statement shall not be used.
<s>[INST] find the error in this code: int main() { int i; for (i = 0; i < 10; ++i) { if (i == 5) { break; } else { break; // Violation of Rule 14.6 } } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.6 - For any iteration statement there shall be at most one break statement used for loop termination.
<s>[INST] find the error in this code: int main() { int i; while (i < 10) { if (i == 5) { break; } else { break; // Violation of Rule 14.6 } } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.6 - For any iteration statement there shall be at most one break statement used for loop termination.
<s>[INST] find the error in this code: int function(int x) { if (x > 0) { return x * 2; } else { return x * 3; // Violation of Rule 14.7 } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.7 - A function shall have a single point of exit at the end of the function.
<s>[INST] find the error in this code: int function(int x) { int result; if (x > 0) { result = x * 2; } else { result = x * 3; // Violation of Rule 14.7 } return result; } [/INST] The error is violation of MISRA C:2012 Rule 14.7 - A function shall have a single point of exit at the end of the function.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: x++; } // Violation of Rule 14.8 return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement.
<s>[INST] find the error in this code: int main() { int x = 5; while (x > 0) x--; // Violation of Rule 14.8 return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { // Do something } else if (x == 10) { // Do something else } // Violation of Rule 14.9 return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.9 - An if ... else if construct shall be terminated with an else statement.
<s>[INST] find the error in this code: int main() { int x = 5; goto end; // Violation of Rule 15.1 end: return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.1 - The goto statement shall not be used.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { goto end; // Violation of Rule 15.1 } end: return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.1 - The goto statement shall not be used.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { // Do something } else if (x == 10) { // Do something else } // Violation of Rule 14.10 return 0; } [/INST] The error is violation of MISRA C:2012 Rule 14.10 - All if ... else if constructs shall be terminated with an else statement.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { // Do something } else if (x == 10) { // Do something else } else { // Do something different } return 0; } [/INST] There are no violations of Rule 14.10 in this code.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { // Do something } else if (x == 10) { // Do something else } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.0 - The MISRA C switch syntax shall be used.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; case 10: // Do something else break; } return 0; } [/INST] There are no violations of Rule 15.0 in this code.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; } return 0; } [/INST] There are no violations of Rule 15.1 in this code.
<s>[INST] find the error in this code: int main() { int x = 5; if (x == 5) { switch (x) { // Violation of Rule 15.1 case 5: // Do something break; } } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.1 - A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something // Missing break statement case 10: // Do something else break; } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.2 - An unconditional break statement shall terminate every non-empty switch clause.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; case 10: // Do something else break; } return 0; } [/INST] There are no violations of Rule 15.2 in this code.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; default: // Do something else break; case 10: // Violation of Rule 15.3 // Do something different break; } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.3 - The final clause of a switch statement shall be the default clause.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; case 10: // Do something different break; default: // Do something else break; } return 0; } [/INST] There are no violations of Rule 15.3 in this code.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x == 5) { // Violation of Rule 15.4 case 1: // Do something break; default: // Do something else break; } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.4 - A switch expression shall not represent a value that is effectively Boolean.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; case 10: // Do something different break; } return 0; } [/INST] There are no violations of Rule 15.4 in this code.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { // Violation of Rule 15.5 // No case clauses } return 0; } [/INST] The error is violation of MISRA C:2012 Rule 15.5 - Every switch statement shall have at least one case clause.
<s>[INST] find the error in this code: int main() { int x = 5; switch (x) { case 5: // Do something break; default: // Do something else break; } return 0; } [/INST] There are no violations of Rule 15.5 in this code.
<s>[INST] find the error in this code: void function(int x, ...) { // Violation of Rule 16.1 // Do something } [/INST] The error is violation of MISRA C:2012 Rule 16.1 - Functions shall not be defined with variable numbers of arguments.
<s>[INST] find the error in this code: void function() { function(); // Violation of Rule 16.2 } [/INST] The error is violation of MISRA C:2012 Rule 16.2 - Functions shall not call themselves, either directly or indirectly.
<s>[INST] find the error in this code: void function(int); // Violation of Rule 16.3 void function(int x) { // Do something } [/INST] The error is violation of MISRA C:2012 Rule 16.3 - Identifiers shall be given for all of the parameters in a function prototype declaration.
<s>[INST] find the error in this code: void function(int x); void function(int x) { // Do something } [/INST] There are no violations of Rule 16.3 in this code.
<s>[INST] find the error in this code: void function(int x); void another_function(int y) { // Do something } [/INST] There are no violations of Rule 16.4 in this code.
<s>[INST] find the error in this code: void function(int x); void function(int y) { // Do something } [/INST] The error is violation of MISRA C:2012 Rule 16.4 - The identifiers used in the declaration and definition of a function shall be identical.
<s>[INST] find the error in this code: void function(); // Violation of Rule 16.5 void function(void) { // Do something } [/INST] The error is violation of MISRA C:2012 Rule 16.5 - Functions with no parameters shall be declared and defined with the parameter list void.
<s>[INST] find the error in this code: void function(void); void function(void) { // Do something } [/INST] There are no violations of Rule 16.5 in this code.
<s>[INST] find the error in this code: void function(int x, int y) { // Do something } int main() { function(5); // Violation of Rule 16.6 return 0; } [/INST] The error is violation of MISRA C:2012 Rule 16.6 - The number of arguments passed to a function shall match the number of parameters.
<s>[INST] find the error in this code: void function(int x, int y) { // Do something } int main() { function(5, 10); return 0; } [/INST] There are no violations of Rule 16.6 in this code.
<s>[INST] find the error in this code: void function(int* x) { // Do something } int main() { int num = 5; function(&num); // Violation of Rule 16.7 return 0; } [/INST] The error is violation of MISRA C:2012 Rule 16.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 object.
<s>[INST] find the error in this code: void function(const int* x) { // Do something } int main() { int num = 5; function(&num); return 0; } [/INST] There are no violations of Rule 16.7 in this code.
<s>[INST] find the error in this code: int function() { if (condition) { return 1; } // No return statement on all paths - Violation of Rule 16.8 } [/INST] The error is violation of MISRA C:2012 Rule 16.8 - All exit paths from a function with non-void return type shall have an explicit return statement with an expression.
<s>[INST] find the error in this code: int function() { if (condition) { return 1; } return 0; // Explicit return statement on all paths } [/INST] There are no violations of Rule 16.8 in this code.
<s>[INST] find the error in this code: int function; // Violation of Rule 16.9 int main() { int result = function(); return 0; } [/INST] The error is violation of MISRA C:2012 Rule 16.9 - A function identifier shall only be used with either a preceding &, or with a parenthesized parameter list, which may be empty.
<s>[INST] find the error in this code: int function(void); int main() { int result = function(); return 0; } [/INST] There are no violations of Rule 16.9 in this code.
<s>[INST] find the error in this code: int function() { // Do something return 0; // Violation of Rule 16.10 } int main() { function(); return 0; } [/INST] The error is violation of MISRA C:2012 Rule 16.10 - If a function returns error information, then that error information shall be tested.
<s>[INST] find the error in this code: int function() { // Do something return 0; } int main() { int result = function(); if (result != 0) { // Handle error } return 0; } [/INST] There are no violations of Rule 16.10 in this code.