26 lines · cpp
1// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t2// RUN: not %run %t 2>&1 | FileCheck %s3//4// REQUIRES: stable-runtime5// MSVC doesn't support VLAs6// UNSUPPORTED: msvc7 8#include "defines.h"9#include <assert.h>10#include <stdint.h>11 12ATTRIBUTE_NOINLINE void foo(int index, int len) {13 if (index > len) {14 char str[len];15 assert(!(reinterpret_cast<uintptr_t>(str) & 31L));16 str[index] = '1'; // BOOM17// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]18// CHECK: WRITE of size 1 at [[ADDR]] thread T019 }20}21 22int main(int argc, char **argv) {23 foo(33, 10);24 return 0;25}26