blob: e1ff66ccf4dc186072f56cebf66b37cf9ce235a3 [file] [log] [blame]
Ted Kremenek565e4652010-02-05 02:06:54 +00001// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-experimental-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s
Zhongxing Xu3ed04d32010-01-18 08:54:31 +00002
3typedef __typeof(sizeof(int)) size_t;
4void *malloc(size_t);
Zhongxing Xu20f01782008-11-24 02:19:49 +00005
6char f1() {
7 char* s = "abcd";
Ted Kremenekf9e96842009-01-22 20:36:33 +00008 char c = s[4]; // no-warning
Zhongxing Xu58e689f2009-11-11 12:33:27 +00009 return s[5] + c; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
Zhongxing Xu20f01782008-11-24 02:19:49 +000010}
Zhongxing Xu3ed04d32010-01-18 08:54:31 +000011
12void f2() {
13 int *p = malloc(12);
14 p[3] = 4; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
15}
Zhongxing Xu9618b852010-04-01 08:20:27 +000016
17struct three_words {
18 int c[3];
19};
20
21struct seven_words {
22 int c[7];
23};
24
25void f3() {
26 struct three_words a, *p;
27 p = &a;
28 p[0] = a; // no-warning
29 p[1] = a; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
30}
31
32void f4() {
33 struct seven_words c;
34 struct three_words a, *p = (struct three_words *)&c;
35 p[0] = a; // no-warning
36 p[1] = a; // no-warning
37 p[2] = a; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
38}