2019-12-31 06:08:04 +01:00
|
|
|
// make USE_Z3=yes
|
|
|
|
// ./cppcheck --verify --inline-suppr --enable=information test/testsuites/danmar-verify/divbyzero.cpp
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <map>
|
2019-12-28 22:23:11 +01:00
|
|
|
|
2019-12-30 09:44:49 +01:00
|
|
|
struct S { int x; };
|
|
|
|
|
|
|
|
int globalvar;
|
|
|
|
|
2020-01-09 10:48:43 +01:00
|
|
|
void dostuff();
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int callfunc1() {
|
2019-12-30 09:44:49 +01:00
|
|
|
int x = 16;
|
|
|
|
scanf("%i\n", &x);
|
|
|
|
// cppcheck-suppress verificationDivByZero
|
|
|
|
return 100000 / x;
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int float1(float f) {
|
2019-12-30 09:44:49 +01:00
|
|
|
// cppcheck-suppress verificationDivByZero
|
2019-12-31 06:08:04 +01:00
|
|
|
return 100000 / (int)f;
|
2019-12-30 09:44:49 +01:00
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
float float2(float f) {
|
2019-12-31 06:08:04 +01:00
|
|
|
// cppcheck-suppress verificationDivByZeroFloat
|
|
|
|
return 100000 / f;
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int functionCall() {
|
|
|
|
#ifdef __clang__
|
|
|
|
return 0;
|
|
|
|
#else
|
2019-12-28 22:23:11 +01:00
|
|
|
// cppcheck-suppress verificationDivByZero
|
2019-12-31 06:08:04 +01:00
|
|
|
return 100000 / unknown_function();
|
2020-01-14 10:28:05 +01:00
|
|
|
#endif
|
2019-12-28 22:23:11 +01:00
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int 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
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int globalVar2() {
|
2020-01-09 10:48:43 +01:00
|
|
|
globalvar = 123;
|
|
|
|
dostuff();
|
|
|
|
// cppcheck-suppress verificationDivByZero
|
|
|
|
return 100000 / globalvar;
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int 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
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int pointer2(int *p) {
|
2019-12-31 06:08:04 +01:00
|
|
|
// cppcheck-suppress verificationDivByZero
|
|
|
|
return 100000 / p[32];
|
2019-12-30 19:47:18 +01:00
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int stdmap(std::map<int,int> &data) {
|
2019-12-28 22:23:11 +01:00
|
|
|
// cppcheck-suppress verificationDivByZero
|
|
|
|
return 100000 / data[43];
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int struct1(struct S *s) {
|
2019-12-28 22:23:11 +01:00
|
|
|
// cppcheck-suppress verificationDivByZero
|
|
|
|
return 100000 / s->x;
|
|
|
|
}
|
2020-01-09 10:48:43 +01:00
|
|
|
|
2020-01-14 10:28:05 +01:00
|
|
|
int trycatch() {
|
2020-01-09 10:48:43 +01:00
|
|
|
int x = 0;
|
|
|
|
try {
|
|
|
|
dostuff();
|
|
|
|
x = 1;
|
|
|
|
} catch (...) {}
|
|
|
|
// cppcheck-suppress verificationDivByZero
|
|
|
|
return 100000 / x;
|
|
|
|
}
|