1 // Regression test for 2 // https://code.google.com/p/address-sanitizer/issues/detail?id=183 3 4 // RUN: %clangxx_asan -O2 %s -o %t 5 // RUN: not %run %t 12 2>&1 | FileCheck %s 6 // RUN: not %run %t 100 2>&1 | FileCheck %s 7 // RUN: not %run %t 10000 2>&1 | FileCheck %s 8 9 #include <stdlib.h> 10 #include <string.h> 11 12 int main(int argc, char *argv[]) { 13 int *x = new int[5]; 14 memset(x, 0, sizeof(x[0]) * 5); 15 int index = atoi(argv[1]); 16 int res = x[index]; 17 // CHECK: AddressSanitizer: {{(heap-buffer-overflow|SEGV)}} 18 // CHECK: #0 0x{{.*}} in main {{.*}}heap-overflow-large.cc:[[@LINE-2]] 19 // CHECK: AddressSanitizer can not {{(provide additional info|describe address in more detail \(wild memory access suspected\))}} 20 // CHECK: SUMMARY: AddressSanitizer: {{(heap-buffer-overflow|SEGV)}} 21 delete[] x; 22 return res; 23 } 24