blob: cfdd7f4e1a83fc4d40b3dd2cd69c81f7af3dd940 [file] [log] [blame]
Ted Kremenek033a07e2011-08-03 23:14:55 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.unix,core.uninitialized -analyzer-store=region -verify %s
Zhongxing Xua5ce9662010-06-01 03:01:33 +00002typedef __typeof(sizeof(int)) size_t;
3void *malloc(size_t);
4void free(void *);
5
6char stackBased1 () {
7 char buf[2];
8 buf[0] = 'a';
9 return buf[1]; // expected-warning{{Undefined}}
10}
11
12char stackBased2 () {
13 char buf[2];
14 buf[1] = 'a';
15 return buf[0]; // expected-warning{{Undefined}}
16}
17
Anna Zaks7a756462011-09-12 18:07:30 +000018// Exercise the conditional visitor. Radar://10105448
19char stackBased3 (int *x) {
20 char buf[2];
21 int *y;
22 buf[0] = 'a';
23 if (!(y = x)) {
24 return buf[1]; // expected-warning{{Undefined}}
25 }
26 return buf[0];
27}
28
Zhongxing Xua5ce9662010-06-01 03:01:33 +000029char heapBased1 () {
30 char *buf = malloc(2);
31 buf[0] = 'a';
32 char result = buf[1]; // expected-warning{{undefined}}
33 free(buf);
34 return result;
35}
36
37char heapBased2 () {
38 char *buf = malloc(2);
39 buf[1] = 'a';
40 char result = buf[0]; // expected-warning{{undefined}}
41 free(buf);
42 return result;
43}