brintos

brintos / llvm-project-archived public Read only

0
0
Text · 863 B · 35947b3 Raw
24 lines · cpp
1// RUN: %clang_cl_asan %Od %s %Fe%t2// RUN: not %run %t 2>&1 | FileCheck %s3 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 T014  // CHECK-NEXT: {{#0 .* main .*use_after_realloc.cpp}}:[[@LINE-3]]15  // CHECK: [[ADDR]] is located 0 bytes inside of 32-byte region16  // CHECK: freed by thread T0 here:17  // CHECK-NEXT: {{#0 .* realloc }}18  // CHECK: {{ #[1-3] .* main .*use_after_realloc.cpp}}:[[@LINE-9]]19  // CHECK: previously allocated by thread T0 here:20  // CHECK-NEXT: {{#0 .* realloc }}21  // CHECK: {{ #[1-3] .* main .*use_after_realloc.cpp}}:[[@LINE-14]]22  free(buffer);23}24