1// RUN: %clang_cl_asan %Od %s %Fe%t
2// RUN: %env_asan_opts=windows_hook_rtl_allocators=true not %run %t 2>&1 | FileCheck %s
3// UNSUPPORTED: asan-64-bits
4#include <stdio.h>
5#include <windows.h>
6
7int main() {
8 char *oldbuf;
9 size_t sz = 8;
10 HANDLE procHeap = GetProcessHeap();
11 oldbuf = (char *)HeapAlloc(procHeap, 0, sz);
12 char *newbuf = oldbuf;
13 while (oldbuf == newbuf) {
14 sz *= 2;
15 newbuf = (char *)HeapReAlloc(procHeap, 0, oldbuf, sz);
16 }
17
18 newbuf[0] = 'a';
19 oldbuf[0] = 'a';
20 // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
21 // CHECK: WRITE of size 1 at [[WRITE2:0x[0-9a-f]+]] thread T0
22 // CHECK: #0 {{0x[0-9a-f]+ in main.*}}:[[@LINE-3]]
23}
24

source code of compiler-rt/test/asan/TestCases/Windows/heaprealloc.cpp