Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-17.c

raw
1 /* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
2 /* { dg-skip-if "" { powerpc-ibm-aix* } } */
3
4 #include <string.h>
5
6 void test (void)
7 {
8 char buf[10];
9 strcpy (buf, "hello");
10 strcat (buf, " world!"); /* { dg-warning "stack-based buffer overflow" } */
11 /* { dg-message "write of 3 bytes to beyond the end of 'buf'" "" { target *-*-* } .-1 } */
12 }
13
14 /* { dg-begin-multiline-output "" }
15 ┌────┬────┬────┬────┬────┐┌─────┬─────┬─────┐
16 │[0] │[1] │[2] │[3] │[4] ││ [5] │ [6] │ [7] │
17 ├────┼────┼────┼────┼────┤├─────┼─────┼─────┤
18 │' ' │'w' │'o' │'r' │'l' ││ 'd' │ '!' │ NUL │
19 ├────┴────┴────┴────┴────┴┴─────┴─────┴─────┤
20 │ string literal (type: 'char[8]') │
21 └───────────────────────────────────────────┘
22 │ │ │ │ │ │ │ │
23 │ │ │ │ │ │ │ │
24 v v v v v v v v
25 ┌─────┬────────────────────┬────┬──────────────┬────┐┌─────────────────┐
26 │ [0] │ ... │[5] │ ... │[9] ││ │
27 ├─────┼────┬────┬────┬────┬┼────┼──────────────┴────┘│ │
28 │ 'h' │'e' │'l' │'l' │'o' ││NUL │ │after valid range│
29 ├─────┴────┴────┴────┴────┴┴────┴───────────────────┐│ │
30 │ 'buf' (type: 'char[10]') ││ │
31 └───────────────────────────────────────────────────┘└─────────────────┘
32 ├─────────────────────────┬─────────────────────────┤├────────┬────────┤
33 │ │
34 ╭─────────┴────────╮ ╭─────────┴─────────╮
35 │capacity: 10 bytes│ │overflow of 3 bytes│
36 ╰──────────────────╯ ╰───────────────────╯
37 { dg-end-multiline-output "" } */