cppcheck/test/synthetic/data.c

69 lines
1.1 KiB
C
Raw Normal View History

2016-11-02 11:07:04 +01:00
int TestData[10];
int global;
2016-11-04 22:15:41 +01:00
void global() {
global = 1000;
2016-11-04 22:15:41 +01:00
TestData[global] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
int global_array[10];
2016-11-04 22:15:41 +01:00
void global_array() {
global_array[3] = 1000;
2016-11-04 22:15:41 +01:00
TestData[global_array[3]] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
int *global_pointer;
2016-11-04 22:15:41 +01:00
void global_pointer() {
*global_pointer = 1000;
2016-11-04 22:15:41 +01:00
TestData[*global_pointer] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local() {
2016-11-02 11:07:04 +01:00
int local;
local = 1000;
2016-11-04 22:15:41 +01:00
TestData[local] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local_array() {
2016-11-02 11:07:04 +01:00
int local_array[10];
local_array[3] = 1000;
2016-11-04 22:15:41 +01:00
TestData[local_array[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-02 11:07:04 +01:00
int local;
int *local_alias = &local;
*local_alias = 1000;
2016-11-04 22:15:41 +01:00
TestData[*local_alias] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
2016-11-04 22:15:41 +01:00
void local_alias_2() {
int local;
int *local_alias = &local;
local = 1000;
2016-11-04 22:15:41 +01:00
TestData[*local_alias] = 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
}