brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 2b82803 Raw
26 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2// RUN: %clangxx_asan -O1 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3// RUN: %clangxx_asan -O2 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK4// RUN: %clangxx_asan -O3 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK5 6#include <stdio.h>7#include <wchar.h>8 9int main() {10  const wchar_t *src = L"X means dog";11  wchar_t goodArray[12];12  wchar_t *volatile goodDst = goodArray;13  wcscpy(goodDst, src);14 15  wchar_t badArray[7];16  wchar_t *volatile badDst = badArray;17  fprintf(stderr, "Good so far.\n");18  // CHECK-DAG: Good so far.19  fflush(stderr);20  wcscpy(badDst, src); // Boom!21  // CHECK-DAG: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}22  // CHECK-DAG: WRITE of size {{[0-9]+}} at [[ADDR]] thread T023  // CHECK-DAG: #0 {{0x[0-9a-f]+}} in wcscpy24  printf("Should have failed with ASAN error.\n");25}26