Ted Kremenek | 033a07e | 2011-08-03 23:14:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.unix,core.uninitialized -analyzer-store=region -verify %s |
Zhongxing Xu | a5ce966 | 2010-06-01 03:01:33 +0000 | [diff] [blame] | 2 | typedef __typeof(sizeof(int)) size_t; |
| 3 | void *malloc(size_t); |
| 4 | void free(void *); |
| 5 | |
| 6 | char stackBased1 () { |
| 7 | char buf[2]; |
| 8 | buf[0] = 'a'; |
| 9 | return buf[1]; // expected-warning{{Undefined}} |
| 10 | } |
| 11 | |
| 12 | char stackBased2 () { |
| 13 | char buf[2]; |
| 14 | buf[1] = 'a'; |
| 15 | return buf[0]; // expected-warning{{Undefined}} |
| 16 | } |
| 17 | |
Anna Zaks | 7a75646 | 2011-09-12 18:07:30 +0000 | [diff] [blame^] | 18 | // Exercise the conditional visitor. Radar://10105448 |
| 19 | char 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 Xu | a5ce966 | 2010-06-01 03:01:33 +0000 | [diff] [blame] | 29 | char 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 | |
| 37 | char 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 | } |