cppcheck/test/synthetic/controlflow.c

125 lines
1.8 KiB
C
Raw Normal View History

2016-11-02 11:07:04 +01:00
//////////////////////////////
// path sensitive analysis
//////////////////////////////
int buf[2];
int getValue(void); // unknown int value
// arg
// -------------------------------------
2016-11-03 20:16:49 +01:00
void arg_in_if(int a) {
if (a==100)
2016-11-02 11:07:04 +01:00
buf[a] = 0; // BUG
}
2016-11-03 20:16:49 +01:00
void arg_before_if(int a) {
buf[a] = 0; // WARNING
if (a==100) {}
2016-11-02 11:07:04 +01:00
}
2016-11-03 20:16:49 +01:00
void arg_after_if(int a) {
if (a==100) {}
buf[a] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
// var
// -------------------------------------
2016-11-03 20:16:49 +01:00
void var(void) {
int x = 100;
2016-11-02 11:07:04 +01:00
buf[x] = 0; // BUG
}
2016-11-03 20:16:49 +01:00
void var_in_for(void) {
int x;
for (x = 0; x<100; x++) {
buf[x] = 0; // BUG
}
}
void var_after_for(void) {
int x;
for (x = 0; x<100; x++) {}
buf[x] = 0; // BUG
}
void var_in_switch(void) {
2016-11-02 11:07:04 +01:00
int x = getValue();
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;
}
}
2016-11-03 20:16:49 +01:00
void var_before_switch(void) {
2016-11-02 11:07:04 +01:00
int x = getValue();
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;
}
}
2016-11-03 20:16:49 +01:00
void var_after_switch(void) {
int x = getValue();
switch (x) {
case 100:
break;
}
buf[x] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
2016-11-03 20:16:49 +01:00
void var_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
}
}
2016-11-03 20:16:49 +01:00
void var_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
}
2016-11-03 20:16:49 +01:00
// arg+var
// -------------------------------------
void arg_var_assign_in_if(int a) {
2016-11-02 11:07:04 +01:00
int x = 0;
if (a==0)
2016-11-03 20:16:49 +01:00
x = 100;
buf[x] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}
2016-11-03 20:16:49 +01:00
void arg_var_in_while_1(int a) {
2016-11-02 11:07:04 +01:00
int x = 0;
2016-11-03 20:16:49 +01:00
if (a == 100) {}
while (x<a) {
buf[x] = 0; // WARNING
x++;
2016-11-03 20:16:49 +01:00
}
2016-11-02 11:07:04 +01:00
}
2016-11-03 20:16:49 +01:00
void arg_var_in_while_2(int a) {
2016-11-02 11:07:04 +01:00
int x = 0;
while (x<a) {
2016-11-03 20:16:49 +01:00
buf[x] = 0; // WARNING
x++;
2016-11-02 11:07:04 +01:00
}
2016-11-03 20:16:49 +01:00
if (a == 100) {}
}
void arg_var_after_while(int a) {
int x = 0;
if (a == 100) {}
while (x<a)
x++;
buf[x] = 0; // WARNING
2016-11-02 11:07:04 +01:00
}