blob: 927194b13ce7823003125fea8b7dcd198014c7c6 [file] [log] [blame]
Alexey Samsonov60164862012-08-15 08:29:17 +00001// RUN: %clang_asan -m64 -O2 %s -o %t
2// RUN: %t 2>&1 | %symbolizer > %t.output
3// RUN: FileCheck %s < %t.output
4// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
5
6#include <stdlib.h>
7#include <string.h>
8int main(int argc, char **argv) {
9 char *x = (char*)malloc(10 * sizeof(char));
10 memset(x, 0, 10);
11 int res = x[argc * 10]; // BOOOM
12 // CHECK: {{READ of size 1 at 0x.* thread T0}}
13 // CHECK: {{ #0 0x.* in main .*heap-overflow.cc:11}}
14 // CHECK: {{0x.* is located 0 bytes to the right of 10-byte region}}
15 // CHECK: {{allocated by thread T0 here:}}
16
17 // CHECK-Linux: {{ #0 0x.* in .*malloc}}
18 // CHECK-Linux: {{ #1 0x.* in main .*heap-overflow.cc:9}}
19
20 // CHECK-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
21 // CHECK-Darwin: {{ #1 0x.* in malloc_zone_malloc.*}}
22 // CHECK-Darwin: {{ #2 0x.* in malloc.*}}
23 // CHECK-Darwin: {{ #3 0x.* in main heap-overflow.cc:9}}
24 free(x);
25 return res;
26}