cppcheck/test/synthetic/controlflow.c

74 lines
1009 B
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) {
if (a==100)
2016-11-02 11:07:04 +01:00
buf[a] = 0; // BUG
}
void before_if(int a) {
2016-11-03 20:16:49 +01:00
buf[a] = 0; // WARNING
if (a==100) {}
2016-11-02 11:07:04 +01:00
}
void after_if(int a) {
2016-11-03 20:16:49 +01:00
if (a==100) {}
buf[a] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
void in_for(void) {
2016-11-03 20:16:49 +01:00
int x;
for (x = 0; x<100; x++) {
buf[x] = 0; // BUG
}
}
void after_for(void) {
2016-11-03 20:16:49 +01:00
int x;
for (x = 0; x<100; x++) {}
buf[x] = 0; // BUG
}
void in_switch(int x) {
2016-11-02 11:07:04 +01:00
switch (x) {
2016-11-03 20:16:49 +01:00
case 100:
2016-11-02 11:07:04 +01:00
buf[x] = 0; // BUG
break;
}
}
void before_switch(int x) {
2016-11-03 20:16:49 +01:00
buf[x] = 0; // WARNING
2016-11-02 11:07:04 +01:00
switch (x) {
2016-11-03 20:16:49 +01:00
case 100:
2016-11-02 11:07:04 +01:00
break;
}
}
void after_switch(int x) {
2016-11-03 20:16:49 +01:00
switch (x) {
case 100:
break;
}
buf[x] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
void in_while(void) {
2016-11-02 11:07:04 +01:00
int x = 0;
2016-11-03 20:16:49 +01:00
while (x<100) {
2016-11-02 11:07:04 +01:00
buf[x] = 0; // BUG
x++;
2016-11-02 11:07:04 +01:00
}
}
void after_while(void) {
2016-11-02 11:07:04 +01:00
int x = 0;
2016-11-03 20:16:49 +01:00
while (x<100)
x++;
2016-11-02 11:07:04 +01:00
buf[x] = 0; // BUG
}