1 /* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
2 /* { dg-skip-if "requires hosted libstdc++ for stdlib size_t" { ! hostedlib } } */
7 /* Gap of 4, then an overflow of 4. */
9 void test2 (size_t size
)
11 int32_t *buf
= (int32_t *) __builtin_malloc (size
* sizeof(int32_t)); /* { dg-message "\\(1\\) capacity: 'size \\* 4' bytes" "" { target c } } */
12 /* { dg-message "\\(1\\) capacity: '\\(size \\* 4\\)' bytes" "" { target c++ } .-1 } */
15 buf
[size
+ 1] = 42; /* { dg-warning "heap-based buffer overflow" } */
19 /* { dg-begin-multiline-output "" }
27 ┌───────────────────────────────┐ ┌───────────────────┐
28 │buffer allocated on heap at (1)│ │ after valid range │
29 └───────────────────────────────┘ └───────────────────┘
30 ├───────────────┬───────────────┤├───────┬────────┤├─────────┬─────────┤
32 ╭─────────────┴────────────╮ ╭───┴───╮ ╭─────────┴─────────╮
33 │capacity: 'size * 4' bytes│ │4 bytes│ │overflow of 4 bytes│
34 ╰──────────────────────────╯ ╰───────╯ ╰───────────────────╯
36 { dg-end-multiline-output "" } */