1 // RUN: %clang_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 // RUN: %clang_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s 3 // RUN: %clang_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s 4 // RUN: %clang_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 5 6 // When built as C on Linux, strndup is transformed to __strndup. 7 // RUN: %clang_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s 8 9 // Unwind problem on arm: "main" is missing from the allocation stack trace. 10 // UNSUPPORTED: target={{.*windows-msvc.*}},target=s390{{.*}},target=arm{{.*}} && !fast-unwinder-works 11 12 #include <string.h> 13 14 char kChars[] = {'f', 'o', 'o'}; 15 16 int main(int argc, char **argv) { 17 char *copy = strndup(kChars, 3); 18 copy = strndup(kChars, 10); 19 // CHECK: AddressSanitizer: global-buffer-overflow 20 // CHECK: {{.*}}main {{.*}}.cpp:[[@LINE-2]] 21 return *copy; 22 } 23