1// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
2// RUN: not %run %t 2>&1 | FileCheck %s
3//
4// REQUIRES: stable-runtime
5
6// MSVC doesn't support VLAs
7// UNSUPPORTED: msvc
8
9#include <assert.h>
10#include <stdint.h>
11
12void foo(int index, int len) {
13 for (int i = 1; i < len; ++i) {
14 char array[len];
15 assert(!(reinterpret_cast<uintptr_t>(array) & 31L));
16 array[index + i] = 0;
17// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
18// CHECK: WRITE of size 1 at [[ADDR]] thread T0
19 }
20}
21
22int main(int argc, char **argv) {
23 foo(index: 9, len: 21);
24 return 0;
25}
26

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of compiler-rt/test/asan/TestCases/vla_loop_overfow.cpp