undef-buffers.c revision 033a07e5fca459ed184369cfee7c90d82367a93a
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.unix,core.uninitialized -analyzer-store=region -verify %s 2typedef __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 18char 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 26char 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} 33