Skip to content

Commit 2d10fdd

Browse files
committed
[analyzer] Add buffer overflow test case.
llvm-svn: 156659
1 parent e40f5d3 commit 2d10fdd

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

clang/test/Analysis/outofbound.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,39 @@ int symbolic_index2(int a) {
8686
}
8787
return 0;
8888
}
89+
90+
int overflow_binary_search(double in) {
91+
int eee = 16;
92+
if (in < 1e-8 || in > 1e23) {
93+
return 0;
94+
} else {
95+
static const double ins[] = {1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1,
96+
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
97+
1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15,
98+
1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
99+
if (in < ins[eee]) {
100+
eee -= 8;
101+
} else {
102+
eee += 8;
103+
}
104+
if (in < ins[eee]) {
105+
eee -= 4;
106+
} else {
107+
eee += 4;
108+
}
109+
if (in < ins[eee]) {
110+
eee -= 2;
111+
} else {
112+
eee += 2;
113+
}
114+
if (in < ins[eee]) {
115+
eee -= 1;
116+
} else {
117+
eee += 1;
118+
}
119+
if (in < ins[eee]) { // expected-warning {{Access out-of-bound array element (buffer overflow)}}
120+
eee -= 1;
121+
}
122+
}
123+
return eee;
124+
}

0 commit comments

Comments
 (0)