brintos

brintos / llvm-project-archived public Read only

0
0
Text · 654 B · a70a86e Raw
27 lines · cpp
1// RUN: %clang_cl_asan %Od %s %Fe%t2// RUN: not %run %t 2>&1 | FileCheck %s3 4class Parent {5 public:6  int field;7};8 9class Child : public Parent {10 public:11  int extra_field;12};13 14int main(void) {15  Parent *p = new Parent;16  Child *c = (Child*)p;  // Intentional error here!17  c->extra_field = 42;18// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]19// CHECK: WRITE of size 4 at [[ADDR]] thread T020// CHECK:   {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_heap.cpp}}:[[@LINE-3]]21// CHECK: [[ADDR]] is located 0 bytes after 4-byte region22// CHECK: allocated by thread T0 here:23// CHECK:   #0 {{.*}} operator new24  return 0;25}26 27