text
stringlengths 110
791
|
---|
<s>[INST] find the error in this code:
int main() {
signed char c = 'A'; // Violation of Rule 6.1
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.1 - The plain char type shall be used only for the storage and use of character values. |
<s>[INST] find the error in this code:
int main() {
unsigned char c = 65;
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.2 - Signed and unsigned char type shall be used only for the storage and use of numeric values. |
<s>[INST] find the error in this code:
int main() {
char c = 'A'; // Violation of Rule 6.2
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.2 - Signed and unsigned char type shall be used only for the storage and use of numeric values. |
<s>[INST] find the error in this code:
typedef int INT32;
typedef unsigned int UINT32;
INT32 main() {
UINT32 x = 100; // Violation of Rule 6.3
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.3 - Typedefs that indicate size and signedness should be used in place of the basic numerical types. |
<s>[INST] find the error in this code:
typedef short int INT16;
typedef unsigned short int UINT16;
INT16 main() {
UINT16 x = 100; // Violation of Rule 6.3
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.3 - Typedefs that indicate size and signedness should be used in place of the basic numerical types. |
<s>[INST] find the error in this code:
struct Flags {
unsigned long int flag : 1; // Violation of Rule 6.4
};
int main() {
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.4 - Bit fields shall only be defined to be of type unsigned int or signed int. |
<s>[INST] find the error in this code:
struct Flags {
signed char flag : 1; // Violation of Rule 6.4
};
int main() {
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.4 - Bit fields shall only be defined to be of type unsigned int or signed int. |
<s>[INST] find the error in this code:
struct Flags {
signed int flag : 1; // Violation of Rule 6.5
};
int main() {
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 6.5 - Bit fields of signed type shall be at least 2 bits long. |
<s>[INST] find the error in this code:
int main() {
int x = 075; // Violation of Rule 7.1
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 7.1 - Octal constants (other than zero) and octal escape sequences shall not be used. |
<s>[INST] find the error in this code:
int add(int a, int b); // Violation of Rule 8.1
int main() {
int sum = add(5, 3);
return 0;
}
int add(int a, int b) {
return a + b;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.1 - Functions shall have prototype declarations and prototype shall be visible at both the function definition and call. |
<s>[INST] find the error in this code:
void printMessage(char msg[]); // Violation of Rule 8.1
int main() {
printMessage("Hello, World!");
return 0;
}
void printMessage(char msg[]) {
printf("%s\n", msg);
}
[/INST] The error is violation of MISRA C:2012 Rule 8.1 - Functions shall have prototype declarations and prototype shall be visible at both the function definition and call. |
<s>[INST] find the error in this code:
int main() {
x = 10; // Violation of Rule 8.2
return 0;
}
int x;
[/INST] The error is violation of MISRA C:2012 Rule 8.2 - Whenever an object or function is declared or defined, its type shall be explicitly stated. |
<s>[INST] find the error in this code:
int main() {
return add(5, 3); // Violation of Rule 8.2
}
int add(int a, int b) {
return a + b;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.2 - Whenever an object or function is declared or defined, its type shall be explicitly stated. |
<s>[INST] find the error in this code:
int add(int a, float b); // Violation of Rule 8.3
int main() {
int result = add(5, 3);
return 0;
}
int add(int a, float b) {
return a + b;
}
[/INST] The error is violation of MISRA C:2012 Rule 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. |
<s>[INST] find the error in this code:
int subtract(int a, int b); // Violation of Rule 8.3
int main() {
int result = subtract(5.0, 3); // Violation of Rule 8.3
return 0;
}
int subtract(int a, int b) {
return a - b;
}
[/INST] The errors are violations of MISRA C:2012 Rule 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. |
<s>[INST] find the error in this code:
int x = 5; // Violation of Rule 8.4
int x = 10;
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.4 - If objects or functions are declared more than once their types shall be compatible. |
<s>[INST] find the error in this code:
int add(int a, int b);
int main() {
return add(5, 3); // Violation of Rule 8.4
}
int add(int a, int b) {
return a + b;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.4 - If objects or functions are declared more than once their types shall be compatible. |
<s>[INST] find the error in this code:
// header.h
int x = 10; // Violation of Rule 8.5
// main.c
#include "header.h"
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.5 - There shall be no definitions of objects or functions in a header file. |
<s>[INST] find the error in this code:
// header.h
void displayMessage() {
printf("Hello, World!\n"); // Violation of Rule 8.5
}
// main.c
#include "header.h"
int main() {
displayMessage();
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.5 - There shall be no definitions of objects or functions in a header file. |
<s>[INST] find the error in this code:
int add(int a, int b) {
return a + b;
} // Violation of Rule 8.6
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.6 - Functions shall be declared at file scope. |
<s>[INST] find the error in this code:
static int multiply(int a, int b) {
return a * b;
} // Violation of Rule 8.6
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.6 - Functions shall be declared at file scope. |
<s>[INST] find the error in this code:
int main() {
int x = 5; // Violation of Rule 8.7
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.7 - Objects shall be defined at block scope if they are only accessed from within a single function. |
<s>[INST] find the error in this code:
int main() {
for (int i = 0; i < 10; ++i) {
int x = i; // Violation of Rule 8.7
// Code
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.7 - Objects shall be defined at block scope if they are only accessed from within a single function. |
<s>[INST] find the error in this code:
// file1.c
int x; // Violation of Rule 8.8
// file2.c
int x; // Violation of Rule 8.8
[/INST] The errors are violations of MISRA C:2012 Rule 8.8 - An external object or function shall be declared in one and only one file. |
<s>[INST] find the error in this code:
// file1.c
int x = 10; // Violation of Rule 8.9
// file2.c
int x = 20; // Violation of Rule 8.9
[/INST] The errors are violations of MISRA C:2012 Rule 8.9 - An identifier with external linkage shall have exactly one external definition. |
<s>[INST] find the error in this code:
static int x; // Violation of Rule 8.10
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.10 - All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required. |
<s>[INST] find the error in this code:
extern int y; // Violation of Rule 8.10
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.10 - All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required. |
<s>[INST] find the error in this code:
int main() {
static int x; // Violation of Rule 8.11
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.11 - The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage. |
<s>[INST] find the error in this code:
int x[] = {1, 2, 3}; // Violation of Rule 8.12
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.12 - When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization. |
<s>[INST] find the error in this code:
extern int x[]; // Violation of Rule 8.12
int main() {
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 8.12 - When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization. |
<s>[INST] find the error in this code:
int main() {
int x; // Violation of Rule 9.1
return x;
}
[/INST] The error is violation of MISRA C:2012 Rule 9.1 - All automatic variables shall have been assigned a value before being used. |
<s>[INST] find the error in this code:
int main() {
int x = 0; // No violation of Rule 9.1
return x;
}
[/INST] No violation of MISRA C:2012 Rule 9.1 |
<s>[INST] find the error in this code:
int main() {
int arr[3] = {1, 2, 3}; // No violation of Rule 9.2
return 0;
}
[/INST] No violation of MISRA C:2012 Rule 9.2 |
<s>[INST] find the error in this code:
int main() {
int arr[3] = {1}; // Violation of Rule 9.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 9.2 - Braces shall be used to indicate and match the structure in the non-zero initialization of arrays and structures. |
<s>[INST] find the error in this code:
enum Colors {
RED = 1,
GREEN,
BLUE = 2 // Violation of Rule 9.3
};
int main() {
// Code
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 9.3 - In an enumerator list, the "=" construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized. |
<s>[INST] find the error in this code:
enum Days {
MONDAY = 1,
TUESDAY = 2,
WEDNESDAY = 3 // No violation of Rule 9.3
};
int main() {
// Code
return 0;
}
[/INST] No violation of MISRA C:2012 Rule 9.3 |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 5;
signed int y = -10;
int sum = x + y; // Violation of Rule 10.1
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.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. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
unsigned int y = 10;
unsigned int diff = x - y; // Violation of Rule 10.1
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.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. |
<s>[INST] find the error in this code:
int func(int a, int b) {
return a + b;
}
int main() {
int (*ptr)(int, int) = func;
void (*ptr2)(void) = (void (*)(void))ptr; // Violation of Rule 10.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.2 - Conversion between a pointer to a function and another type shall not be performed. |
<s>[INST] find the error in this code:
void func() {}
int main() {
void (*ptr)(void) = func;
int (*ptr2)(int, int) = (int (*)(int, int))ptr; // Violation of Rule 10.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.2 - Conversion between a pointer to a function and another type shall not be performed. |
<s>[INST] find the error in this code:
void func() {}
int main() {
int (*ptr)(int, int) = (int (*)(int, int))func; // Violation of Rule 10.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.2 - Conversion between a pointer to a function and another type shall not be performed.
|
<s>[INST] find the error in this code:
int func(int a, int b) {
return a + b;
}
int main() {
int (*ptr)(void) = (int (*)(void))func; // Violation of Rule 10.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.2 - Conversion between a pointer to a function and another type shall not be performed. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 10;
unsigned int y = 20;
int z = (int)(x - y); // Violation of Rule 10.3
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.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. |
<s>[INST] find the error in this code:
int main() {
float x = 10.5f;
float y = 20.3f;
double z = (double)(x * y); // Violation of Rule 10.4
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.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. |
<s>[INST] find the error in this code:
int main() {
double x = 10.5;
double y = 20.3;
float z = (float)(x * y); // Violation of Rule 10.4
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.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. |
<s>[INST] find the error in this code:
int main() {
unsigned char x = 0xFF;
unsigned char y = 0x0F;
unsigned char z = ~(x & y); // Violation of Rule 10.5
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.5 - If 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 operand. |
<s>[INST] find the error in this code:
int main() {
unsigned short x = 0xFFFF;
unsigned short y = 0x00FF;
unsigned short z = (unsigned short)(x << y); // Violation of Rule 10.5
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.5 - If 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 operand. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 10; // Violation of Rule 10.6
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.6 - A "U" suffix shall be applied to all constants of unsigned type. |
<s>[INST] find the error in this code:
int main() {
unsigned long long y = 1000000000000; // Violation of Rule 10.6
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 10.6 - A "U" suffix shall be applied to all constants of unsigned type. |
<s>[INST] find the error in this code:
int main() {
int (*func_ptr)() = NULL;
int x = (int)func_ptr; // Violation of Rule 11.1
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.1 - Conversions shall not be performed between a pointer to a function and any type other than an integral type. |
<s>[INST] find the error in this code:
int main() {
void (*func_ptr)() = NULL;
float y = (float)func_ptr; // Violation of Rule 11.1
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.1 - Conversions shall not be performed between a pointer to a function and any type other than an integral type. |
<s>[INST] find the error in this code:
int main() {
int x = 10;
int *ptr = &x;
float y = (float)ptr; // Violation of Rule 11.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.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. |
<s>[INST] find the error in this code:
int main() {
int x = 10;
void *void_ptr = &x;
float y = (float)void_ptr; // Violation of Rule 11.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.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. |
<s>[INST] find the error in this code:
int main() {
int *ptr = (int *)10; // Violation of Rule 11.3
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.3 - A cast should not be performed between a pointer type and an integral type. |
<s>[INST] find the error in this code:
int main() {
int *ptr = (int *)(void *)10; // Violation of Rule 11.3
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.3 - A cast should not be performed between a pointer type and an integral type. |
<s>[INST] find the error in this code:
int main() {
int x = 10;
double *ptr = (double *)&x; // Violation of Rule 11.4
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.4 - A cast should not be performed between a pointer to object type and a different pointer to object type. |
<s>[INST] find the error in this code:
int main() {
const int x = 10;
int *ptr = (int *)&x; // Violation of Rule 11.5
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.5 - A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer. |
<s>[INST] find the error in this code:
int main() {
volatile int x = 10;
int *ptr = (int *)&x; // Violation of Rule 11.5
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 11.5 - A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer. |
<s>[INST] find the error in this code:
int main() {
int a = 5, b = 10, c = 15;
int result = a + b * c; // Violation of Rule 12.1
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.1 - Limited dependence should be placed on C's operator precedence rules in expressions. |
<s>[INST] find the error in this code:
int main() {
int a = 5, b = 10, c = 15;
int result = a * b + c; // Violation of Rule 12.1
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.1 - Limited dependence should be placed on C's operator precedence rules in expressions. |
<s>[INST] find the error in this code:
int main() {
int a = 5, b = 10, c = 15;
int result = a++ * b; // Violation of Rule 12.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.2 - The value of an expression shall be the same under any order of evaluation that the standard permits. |
<s>[INST] find the error in this code:
int main() {
int a = 5, b = 10, c = 15;
int result = ++a * b; // Violation of Rule 12.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.2 - The value of an expression shall be the same under any order of evaluation that the standard permits. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
int result = sizeof(++x); // Violation of Rule 12.3
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.3 - The sizeof operator shall not be used on expressions that contain side effects. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
int result = sizeof(x++); // Violation of Rule 12.3
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.3 - The sizeof operator shall not be used on expressions that contain side effects. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x > 0 && y++) { // Violation of Rule 12.4
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.4 - The right hand operand of a logical && or || operator shall not contain side effects. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x > 0 || y--) { // Violation of Rule 12.4
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.4 - The right hand operand of a logical && or || operator shall not contain side effects. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x > 0 && y + 1) { // Violation of Rule 12.5
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.5 - The operands of logical operators (&&, ||) should be primary expressions. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if ((x > 0) || (y > 0) && (x < y)) { // Violation of Rule 12.5
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.5 - The operands of logical operators (&&, ||) should be primary expressions. |
<s>[INST] find the error in this code:
int main() {
int i;
for (i = 0; i < 10; i++) {
printf("%d\n", i);
i++; // Violation of Rule 12.6
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop. |
<s>[INST] find the error in this code:
int main() {
int i;
for (i = 0; i < 10; i++) {
printf("%d\n", i);
i += 2; // Violation of Rule 12.6
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop. |
<s>[INST] find the error in this code:
int main() {
int x = -5;
int result = x & 0x0F; // Violation of Rule 12.7
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.7 - Bitwise operators shall not be applied to operands whose underlying type is signed. |
<s>[INST] find the error in this code:
int main() {
int x = -5;
int result = x | 0xFF; // Violation of Rule 12.7
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.7 - Bitwise operators shall not be applied to operands whose underlying type is signed. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
int result = x << 33; // Violation of Rule 12.8
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.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. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 5;
int result = x >> 32; // Violation of Rule 12.8
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.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. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 5;
int result = -x; // Violation of Rule 12.9
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.9 - The unary minus operator shall not be applied to an expression whose underlying type is unsigned. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 5;
int result = -1 * x; // Violation of Rule 12.9
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.9 - The unary minus operator shall not be applied to an expression whose underlying type is unsigned. |
<s>[INST] find the error in this code:
int main() {
int a = 5, b = 10, c;
c = (a++, b++); // Violation of Rule 12.10
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.10 - The comma operator shall not be used. |
<s>[INST] find the error in this code:
int main() {
int x, y;
for (x = 0, y = 10; x < 5; x++, y--) { // Violation of Rule 12.10
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.10 - The comma operator shall not be used. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 4294967295;
unsigned int result = x + 1; // Violation of Rule 12.11
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.11 - Evaluation of constant unsigned integer expressions should not lead to wrap-around. |
<s>[INST] find the error in this code:
int main() {
unsigned int x = 0;
unsigned int result = x - 1; // Violation of Rule 12.11
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.11 - Evaluation of constant unsigned integer expressions should not lead to wrap-around. |
<s>[INST] find the error in this code:
int main() {
float f = 3.14;
int* ptr = (int*)&f; // Violation of Rule 12.12
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.12 - The underlying bit representations of floating-point values shall not be used. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
int z = x++ + y; // Violation of Rule 12.13
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.13 - The increment (++) and decrement (--) operators should not be mixed with other operators in an expression. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
int z = ++x - y; // Violation of Rule 12.13
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 12.13 - The increment (++) and decrement (--) operators should not be mixed with other operators in an expression. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x = y) { // Violation of Rule 13.1
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.1 - Assignment operators shall not be used in expressions that yield a Boolean value. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x += y) { // Violation of Rule 13.1
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.1 - Assignment operators shall not be used in expressions that yield a Boolean value. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
if (x) { // Violation of Rule 13.2
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.2 - Tests of a value against zero should be made explicit, unless the operand is effectively Boolean. |
<s>[INST] find the error in this code:
int main() {
float x = 3.14, y = 2.718;
if (x == y) { // Violation of Rule 13.3
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.3 - Floating-point expressions shall not be tested for equality or inequality. |
<s>[INST] find the error in this code:
int main() {
double x = 1.0 / 3.0, y = 0.33333;
if (x != y) { // Violation of Rule 13.3
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.3 - Floating-point expressions shall not be tested for equality or inequality. |
<s>[INST] find the error in this code:
int main() {
float x = 0.0;
for (; x < 10.0; x++) { // Violation of Rule 13.4
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.4 - The controlling expression of a for statement shall not contain any objects of floating type. |
<s>[INST] find the error in this code:
int main() {
double x = 0.0;
for (; x < 10.0; x += 0.1) { // Violation of Rule 13.4
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.4 - The controlling expression of a for statement shall not contain any objects of floating type. |
<s>[INST] find the error in this code:
int main() {
int i = 0;
for (i = 0; i < 10; printf("i is %d\n", i), i++) { // Violation of Rule 13.5
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.5 - The three expressions of a for statement shall be concerned only with loop control. |
<s>[INST] find the error in this code:
int main() {
int i = 0;
for (i = 0; i < 10; i++, scanf("%d", &i)) { // Violation of Rule 13.5
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.5 - The three expressions of a for statement shall be concerned only with loop control. |
<s>[INST] find the error in this code:
int main() {
int i;
for (i = 0; i < 10; ++i) {
i++; // Violation of Rule 13.6
printf("i = %d\n", i);
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x > y && x < y) { // Violation of Rule 13.7
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.7 - Boolean operations whose results are invariant shall not be permitted. |
<s>[INST] find the error in this code:
int main() {
int x = 5, y = 10;
if (x == y || x != y) { // Violation of Rule 13.7
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 13.7 - Boolean operations whose results are invariant shall not be permitted. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
return 0;
x++; // Violation of Rule 14.1
}
[/INST] The error is violation of MISRA C:2012 Rule 14.1 - There shall be no unreachable code. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
if (x > 0) {
return 0;
}
else {
x++; // Violation of Rule 14.1
}
}
[/INST] The error is violation of MISRA C:2012 Rule 14.1 - There shall be no unreachable code. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
if (x == 5) { // Violation of Rule 14.2
// Do something
}
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 14.2 - All non-null statements shall either (a) have at least one side-effect however executed, or (b) cause control flow to change. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
x = x + 1; // Violation of Rule 14.2
return 0;
}
[/INST] The error is violation of MISRA C:2012 Rule 14.2 - All non-null statements shall either (a) have at least one side-effect however executed, or (b) cause control flow to change. |
<s>[INST] find the error in this code:
int main() {
int x = 5;
if (x > 0) {} // Violation of Rule 14.3
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. |