cppcheck/test/testsuites/danmar-verify/divbyzero.cpp

74 lines
1.4 KiB
C++
Raw Normal View History

2019-12-31 06:08:04 +01:00
// make USE_Z3=yes
// ./cppcheck --verify --inline-suppr --enable=information test/testsuites/danmar-verify/divbyzero.cpp
2019-12-28 22:23:11 +01:00
struct S { int x; };
int globalvar;
void dostuff();
void callfunc1() {
int x = 16;
scanf("%i\n", &x);
// cppcheck-suppress verificationDivByZero
return 100000 / x;
}
2019-12-31 06:08:04 +01:00
void float1(float f) {
// cppcheck-suppress verificationDivByZero
2019-12-31 06:08:04 +01:00
return 100000 / (int)f;
}
2019-12-31 06:08:04 +01:00
void float2(float f) {
// cppcheck-suppress verificationDivByZeroFloat
return 100000 / f;
}
void functionCall() {
2019-12-28 22:23:11 +01:00
// cppcheck-suppress verificationDivByZero
2019-12-31 06:08:04 +01:00
return 100000 / unknown_function();
2019-12-28 22:23:11 +01:00
}
2019-12-31 06:08:04 +01:00
void globalVar1() {
2019-12-28 22:23:11 +01:00
// cppcheck-suppress verificationDivByZero
2019-12-31 06:08:04 +01:00
return 100000 / globalvar;
2019-12-28 22:23:11 +01:00
}
void globalVar1() {
globalvar = 123;
dostuff();
// cppcheck-suppress verificationDivByZero
return 100000 / globalvar;
}
2019-12-31 06:08:04 +01:00
void pointer1(int *p) {
2019-12-28 22:23:11 +01:00
// cppcheck-suppress verificationDivByZero
2019-12-31 06:08:04 +01:00
return 100000 / *p;
2019-12-28 22:23:11 +01:00
}
2019-12-31 06:08:04 +01:00
void pointer2(int *p) {
// cppcheck-suppress verificationDivByZero
return 100000 / p[32];
}
2019-12-28 22:23:11 +01:00
void stdmap(std::map<int,int> &data) {
// cppcheck-suppress verificationDivByZero
return 100000 / data[43];
}
void struct1(struct S *s) {
// cppcheck-suppress verificationDivByZero
return 100000 / s->x;
}
void trycatch() {
int x = 0;
try {
dostuff();
x = 1;
} catch (...) {}
// cppcheck-suppress verificationDivByZero
return 100000 / x;
}