blob: bc681857ae672e900dbf71150162c08c63dbddf4 [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// REQUIRES: asan-64-bits
2// RUN: %clangxx_asan -O3 %s -o %t
3// RUN: not %run %t 2>&1 | FileCheck %s
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07004// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s
5// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE
Stephen Hines6d186232014-11-26 17:56:19 -08006#include <stdio.h>
7#include <stdlib.h>
8struct C {
9 int x;
10 ~C() {
11 fprintf(stderr, "ZZZZZZZZ\n");
12 exit(1);
13 }
14};
15
16int main(int argc, char **argv) {
17 C *buffer = new C[argc];
18 buffer[-2].x = 10;
19// CHECK: AddressSanitizer: heap-buffer-overflow
20// CHECK: in main {{.*}}new_array_cookie_test.cc:[[@LINE-2]]
21// CHECK: is located 0 bytes inside of 12-byte region
22// NO_COOKIE: ZZZZZZZZ
23 delete [] buffer;
24}