forked from cppcheck-opensource/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivbyzero.cpp
More file actions
79 lines (64 loc) · 1.49 KB
/
divbyzero.cpp
File metadata and controls
79 lines (64 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// make USE_Z3=yes
// ./cppcheck --verify --inline-suppr --enable=information test/testsuites/danmar-verify/divbyzero.cpp
#include <stdio.h>
#include <map>
struct S { int x; };
int globalvar;
void dostuff();
int callfunc1() {
int x = 16;
scanf("%i\n", &x);
// cppcheck-suppress verificationDivByZero
return 100000 / x;
}
int float1(float f) {
// cppcheck-suppress verificationDivByZero
return 100000 / (int)f;
}
float float2(float f) {
// cppcheck-suppress verificationDivByZeroFloat
return 100000 / f;
}
int functionCall() {
#ifdef __clang__
return 0;
#else
// cppcheck-suppress verificationDivByZero
return 100000 / unknown_function();
#endif
}
int globalVar1() {
// cppcheck-suppress verificationDivByZero
return 100000 / globalvar;
}
int globalVar2() {
globalvar = 123;
dostuff();
// cppcheck-suppress verificationDivByZero
return 100000 / globalvar;
}
int pointer1(int *p) {
// cppcheck-suppress verificationDivByZero
return 100000 / *p;
}
int pointer2(int *p) {
// cppcheck-suppress verificationDivByZero
return 100000 / p[32];
}
int stdmap(std::map<int,int> &data) {
// cppcheck-suppress verificationDivByZero
return 100000 / data[43];
}
int struct1(struct S *s) {
// cppcheck-suppress verificationDivByZero
return 100000 / s->x;
}
int trycatch() {
int x = 0;
try {
dostuff();
x = 1;
} catch (...) {}
// cppcheck-suppress verificationDivByZero
return 100000 / x;
}