Zhongxing Xu | a5ce966 | 2010-06-01 03:01:33 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store=region -verify %s |
| 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 | |
| 18 | char heapBased1 () { |
| 19 | char *buf = malloc(2); |
| 20 | buf[0] = 'a'; |
| 21 | char result = buf[1]; // expected-warning{{undefined}} |
| 22 | free(buf); |
| 23 | return result; |
| 24 | } |
| 25 | |
| 26 | char heapBased2 () { |
| 27 | char *buf = malloc(2); |
| 28 | buf[1] = 'a'; |
| 29 | char result = buf[0]; // expected-warning{{undefined}} |
| 30 | free(buf); |
| 31 | return result; |
| 32 | } |