17 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s2// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s3// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s4// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s5 6#include <string.h>7int main(int argc, char **argv) {8 char x[10];9 memset(x, 0, 10);10 int res = x[argc * 10]; // BOOOM11 // CHECK: {{READ of size 1 at 0x.* thread T0}}12 // CHECK: {{ #0 0x.* in main .*stack-buffer-overflow.cpp:}}[[@LINE-2]]13 // CHECK: {{Address 0x.* is located in stack of thread T0 at offset}}14 // CHECK-NEXT: in{{.*}}main{{.*}}stack-buffer-overflow.cpp15 return res;16}17