Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clangxx_asan -O0 -fsanitize-address-field-padding=1  %s -o %t
      2 // RUN: not %run %t 11 2>&1 | FileCheck %s
      3 // RUN: %run %t 10
      4 //
      5 // FIXME: fix 32-bits.
      6 // REQUIRES: asan-64-bits
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 class Foo {
     10  public:
     11   Foo() : pre1(1), pre2(2), post1(3), post2(4) {
     12   }
     13   virtual ~Foo() {
     14   }
     15   void set(int i, int val) { a[i] = val; }
     16 // CHECK: ERROR: AddressSanitizer: intra-object-overflow
     17 // CHECK: #0 {{.*}}Foo::set{{.*}}intra-object-overflow.cc:[[@LINE-2]]
     18  private:
     19   int pre1, pre2;
     20   int a[11];
     21   int post1, post2;
     22 };
     23 
     24 int main(int argc, char **argv) {
     25   int idx = argc == 2 ? atoi(argv[1]) : 0;
     26   Foo *foo = new Foo;
     27   foo->set(idx, 42);
     28 // CHECK: #1 {{.*}}main{{.*}}intra-object-overflow.cc:[[@LINE-1]]
     29 // CHECK: is located 84 bytes inside of 128-byte region
     30   delete foo;
     31 }
     32