blob: 535dab1eb9eddee91cb600ca41d155ec537eb2f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
#include <stdint.h>
#include <stdlib.h>
void int_vla_write_element_after_end_off_by_one(int32_t x, size_t n)
{
int32_t arr[n]; /* { dg-message "\\(1\\) capacity: 'n \\* 4' bytes" } */
arr[n] = x; /* { dg-warning "stack-based buffer overflow" } */
}
/* { dg-begin-multiline-output "" }
┌──────────────────────────────────┐
│ write from 'x' (type: 'int32_t') │
└──────────────────────────────────┘
│
│
v
┌──────────────────────────────────┐┌──────────────────────────────────┐
│ buffer allocated on stack at (1) ││ after valid range │
└──────────────────────────────────┘└──────────────────────────────────┘
├────────────────┬─────────────────┤├────────────────┬─────────────────┤
│ │
╭───────────┴───────────╮ ╭─────────┴─────────╮
│capacity: 'n * 4' bytes│ │overflow of 4 bytes│
╰───────────────────────╯ ╰───────────────────╯
{ dg-end-multiline-output "" } */
|