1 // RUN: %clang_analyze_cc1 -Wno-array-bounds -analyzer-store=region -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=unix \
4 // RUN: -analyzer-checker=alpha.security.ArrayBound \
5 // RUN: -analyzer-config unix.DynamicMemoryModeling:Optimistic=true
7 typedef __typeof(sizeof(int)) size_t;
9 void *calloc(size_t, size_t);
13 char c
= s
[4]; // no-warning
14 return s
[5] + c
; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
19 p
[3] = 4; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
31 struct three_words a
, *p
;
33 p
[0] = a
; // no-warning
34 p
[1] = a
; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
39 struct three_words a
, *p
= (struct three_words
*)&c
;
40 p
[0] = a
; // no-warning
41 p
[1] = a
; // no-warning
42 p
[2] = a
; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
46 char *p
= calloc(2,2);
47 p
[3] = '.'; // no-warning
48 p
[4] = '!'; // expected-warning{{out-of-bound}}
54 b
[1] = 3; // expected-warning{{out-of-bound}}
59 a
.c
[3] = 1; // expected-warning{{out-of-bound}}
65 x
[4] = 4; // no-warning
66 x
[5] = 5; // expected-warning{{out-of-bound}}
70 void alloca_region(int a
) {
72 char *x
= __builtin_alloca(a
);
73 x
[4] = 4; // no-warning
74 x
[5] = 5; // expected-warning{{out-of-bound}}
78 int symbolic_index(int a
) {
81 return x
[a
]; // expected-warning{{out-of-bound}}
86 int symbolic_index2(int a
) {
89 return x
[a
]; // expected-warning{{out-of-bound}}
94 int overflow_binary_search(double in
) {
96 if (in
< 1e-8 || in
> 1e23
) {
99 static const double ins
[] = {1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1,
100 1e0
, 1e1
, 1e2
, 1e3
, 1e4
, 1e5
, 1e6
, 1e7
,
101 1e8
, 1e9
, 1e10
, 1e11
, 1e12
, 1e13
, 1e14
, 1e15
,
102 1e16
, 1e17
, 1e18
, 1e19
, 1e20
, 1e21
, 1e22
};
123 if (in
< ins
[eee
]) { // expected-warning {{Access out-of-bound array element (buffer overflow)}}