cppcheck/test/synthetic/data.c

69 lines
988 B
C
Raw Normal View History

2016-11-02 11:07:04 +01:00
int TestData[10];
2016-11-07 09:30:17 +01:00
int g;
2016-11-04 22:15:41 +01:00
void global() {
2016-11-07 09:30:17 +01:00
g = 1000;
TestData[g] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-07 09:30:17 +01:00
int garr[10];
2016-11-04 22:15:41 +01:00
void global_array() {
2016-11-07 09:30:17 +01:00
garr[3] = 1000;
TestData[garr[3]] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-07 09:30:17 +01:00
int *gp;
2016-11-04 22:15:41 +01:00
void global_pointer() {
2016-11-07 09:30:17 +01:00
*gp = 1000;
TestData[*gp] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local() {
2016-11-07 09:30:17 +01:00
int x;
x = 1000;
TestData[x] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local_array() {
2016-11-07 09:30:17 +01:00
int arr[10];
arr[3] = 1000;
TestData[arr[3]] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local_alias_1() {
2016-11-07 09:30:17 +01:00
int x;
int *p = &x;
*p = 1000;
TestData[*p] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local_alias_2() {
2016-11-07 09:30:17 +01:00
int x;
int *p = &x;
x = 1000;
TestData[*p] = 0; // BUG
}
2016-11-02 11:07:04 +01:00
struct ABC {
int a;
int b[10];
int c;
2016-11-02 11:07:04 +01:00
};
2016-11-04 22:15:41 +01:00
void struct_member_init() {
struct ABC abc = {1000,{0},3};
2016-11-04 22:15:41 +01:00
TestData[abc.a] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void struct_member_assign(struct ABC *abc) {
abc->a = 1000;
2016-11-04 22:15:41 +01:00
TestData[abc->a] = 0; // BUG
}
2016-11-02 11:07:04 +01:00
2016-11-04 22:15:41 +01:00
void struct_arraymember(struct ABC *abc) {
abc->b[3] = 1000;
2016-11-04 22:15:41 +01:00
TestData[abc->b[3]] = 0; // BUG
}