cppcheck/test/synthetic/controlflow.c

74 lines
1.1 KiB
C
Raw Normal View History

2016-11-02 11:07:04 +01:00
//////////////////////////////
// control flow analysis
2016-11-02 11:07:04 +01:00
//////////////////////////////
int buf[2];
void in_if(int a) {
2021-08-07 20:51:18 +02:00
if (a==100)
buf[a] = 0; // BUG
2016-11-02 11:07:04 +01:00
}
void before_if(int a) {
2021-08-07 20:51:18 +02:00
buf[a] = 0; // WARNING
if (a==100) {}
2016-11-02 11:07:04 +01:00
}
void after_if(int a) {
2021-08-07 20:51:18 +02:00
if (a==100) {}
buf[a] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
void in_for(void) {
2021-08-07 20:51:18 +02:00
int x;
for (x = 0; x<100; x++) {
buf[x] = 0; // BUG
}
2016-11-03 20:16:49 +01:00
}
void after_for(void) {
2021-08-07 20:51:18 +02:00
int x;
for (x = 0; x<100; x++) {}
buf[x] = 0; // BUG
2016-11-03 20:16:49 +01:00
}
void in_switch(int x) {
2021-08-07 20:51:18 +02:00
switch (x) {
case 100:
buf[x] = 0; // BUG
break;
}
2016-11-02 11:07:04 +01:00
}
void before_switch(int x) {
2021-08-07 20:51:18 +02:00
buf[x] = 0; // WARNING
switch (x) {
case 100:
break;
}
2016-11-02 11:07:04 +01:00
}
void after_switch(int x) {
2021-08-07 20:51:18 +02:00
switch (x) {
case 100:
break;
}
buf[x] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
void in_while(void) {
2021-08-07 20:51:18 +02:00
int x = 0;
while (x<100) {
buf[x] = 0; // BUG
x++;
}
2016-11-02 11:07:04 +01:00
}
void after_while(void) {
2021-08-07 20:51:18 +02:00
int x = 0;
while (x<100)
x++;
buf[x] = 0; // BUG
2016-11-02 11:07:04 +01:00
}