use_after_realloc.cc revision 5d71de26cedae3dafc17449fe0182045c0bd20e8
1// RUN: %clang_cl_asan -O0 %s -Fe%t
2// RUN: not %run %t 2>&1 | FileCheck %s
3
4#include <malloc.h>
5
6int main() {
7  char *buffer = (char*)realloc(0, 32),
8       *stale = buffer;
9  buffer = (char*)realloc(buffer, 64);
10  // The 'stale' may now point to a free'd memory.
11  stale[0] = 42;
12// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
13// CHECK: WRITE of size 1 at [[ADDR]] thread T0
14// CHECK-NEXT: {{#0 .* main .*use_after_realloc.cc}}:[[@LINE-3]]
15// CHECK: [[ADDR]] is located 0 bytes inside of 32-byte region
16// CHECK: freed by thread T0 here:
17// CHECK-NEXT: {{#0 .* realloc }}
18// CHECK-NEXT: {{#1 .* main .*use_after_realloc.cc}}:[[@LINE-9]]
19// CHECK: previously allocated by thread T0 here:
20// CHECK-NEXT: {{#0 .* realloc }}
21// CHECK-NEXT: {{#1 .* main .*use_after_realloc.cc}}:[[@LINE-14]]
22  free(buffer);
23}
24