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