Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-strcat.c

raw
1 /* { dg-additional-options "-fdiagnostics-text-art-charset=unicode -Wno-stringop-overflow" } */
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, "foo");
10 strcat (buf, " bar");
11 strcat (buf, " baz!"); /* { dg-warning "stack-based buffer overflow" } */
12 }
13
14 /* { dg-begin-multiline-output "" }
15
16 ┌────┬────┬────┐ ┌────┬────┬───────┐
17 │[0] │[1] │[2] │ │[3] │[4] │ [5] │
18 ├────┼────┼────┤ ├────┼────┼───────┤
19 │' ' │'b' │'a' │ │'z' │'!' │ NUL │
20 ├────┴────┴────┴─┴────┴────┴───────┤
21 │ string literal (type: 'char[6]') │
22 └──────────────────────────────────┘
23 │ │ │ │ │ │
24 │ │ │ │ │ │
25 v v v v v v
26 ┌─────┬─────────────────────────────┬────┬────┬────┐ ┌─────────────────┐
27 │ [0] │ ... │[7] │... │[9] │ │ │
28 └─────┴────────┬────┬────┬────┬────┬┼────┼────┴────┘ │ │
29 │' ' │'b' │'a' │'r' ││NUL │ │after valid range│
30 ┌──────────────┴────┴────┴────┴────┴┴────┴─────────┐ │ │
31 │ 'buf' (type: 'char[10]') │ │ │
32 └──────────────────────────────────────────────────┘ └─────────────────┘
33 ├────────────────────────┬─────────────────────────┤ ├────────┬────────┤
34 │ │
35 ╭─────────┴────────╮ ╭─────────┴─────────╮
36 │capacity: 10 bytes│ │overflow of 3 bytes│
37 ╰──────────────────╯ ╰───────────────────╯
38
39 { dg-end-multiline-output "" { target c } } */
40
41 /* { dg-begin-multiline-output "" }
42
43 ┌─────┬─────┬─────┐ ┌─────┬─────┬─────┐
44 │ [0] │ [1] │ [2] │ │ [3] │ [4] │ [5] │
45 ├─────┼─────┼─────┤ ├─────┼─────┼─────┤
46 │ ' ' │ 'b' │ 'a' │ │ 'z' │ '!' │ NUL │
47 ├─────┴─────┴─────┴──┴─────┴─────┴─────┤
48 │string literal (type: 'const char[6]')│
49 └──────────────────────────────────────┘
50 │ │ │ │ │ │
51 │ │ │ │ │ │
52 v v v v v v
53 ┌────┬──────────────────────────┬─────┬─────┬─────┐ ┌─────────────────┐
54 │[0] │ ... │ [7] │ ... │ [9] │ │ │
55 └────┴───────┬────┬────┬───┬───┬┼─────┼─────┴─────┘ │ │
56 │' ' │'b' │'a'│'r'││ NUL │ │after valid range│
57 ┌────────────┴────┴────┴───┴───┴┴─────┴───────────┐ │ │
58 │ 'char buf [10]' (type: 'char[10]') │ │ │
59 └─────────────────────────────────────────────────┘ └─────────────────┘
60 ├────────────────────────┬────────────────────────┤ ├────────┬────────┤
61 │ │
62 ╭─────────┴────────╮ ╭─────────┴─────────╮
63 │capacity: 10 bytes│ │overflow of 3 bytes│
64 ╰──────────────────╯ ╰───────────────────╯
65
66 { dg-end-multiline-output "" { target c++ } } */