cppcheck/test/synthetic/data.c

69 lines
1.0 KiB
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() {
2021-08-07 20:51:18 +02: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() {
2021-08-07 20:51:18 +02: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() {
2021-08-07 20:51:18 +02: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() {
2021-08-07 20:51:18 +02: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() {
2021-08-07 20:51:18 +02: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() {
2021-08-07 20:51:18 +02: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() {
2021-08-07 20:51:18 +02:00
int x;
int *p = &x;
x = 1000;
TestData[*p] = 0; // BUG
}
2016-11-02 11:07:04 +01:00
struct ABC {
2021-08-07 20:51:18 +02:00
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() {
2021-08-07 20:51:18 +02:00
struct ABC abc = {1000,{0},3};
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) {
2021-08-07 20:51:18 +02:00
abc->a = 1000;
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) {
2021-08-07 20:51:18 +02:00
abc->b[3] = 1000;
TestData[abc->b[3]] = 0; // BUG
}