Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-19.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 #define LOREM_IPSUM \
7 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod" \
8 " tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" \
9 " veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" \
10 " commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" \
11 " velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" \
12 " occaecat cupidatat non proident, sunt in culpa qui officia deserunt" \
13 " mollit anim id est laborum."
14
15 void
16 test_long_string ()
17 {
18 char buf[100];
19 strcpy (buf, "abc ");
20 strcat (buf, LOREM_IPSUM); /* { dg-warning "stack-based buffer overflow" } */
21 /* { dg-message "write of 350 bytes to beyond the end of 'buf'" "" { target *-*-* } .-1 } */
22 }
23
24 /* { dg-begin-multiline-output "" }
25 ┌───┬───┬───┬───┬───┬───┬───────┬─────┬─────┬─────┬─────┬─────┬─────┐
26 │[0]│[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│
27 ├───┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤
28 │'L'│'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │
29 ├───┴───┴───┴───┴───┴───┴───────┴─────┴─────┴─────┴─────┴─────┴─────┤
30 │ string literal (type: 'char[446]') │
31 └───────────────────────────────────────────────────────────────────┘
32 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
33 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
34 v v v v v v v v v v v v v v v
35 ┌───┬────────────┬───┬────────────────────┬────┐┌────────────────────────────────────┐
36 │[0]│ ... │[4]│ ... │[99]││ │
37 ├───┼───┬───┬───┬┼───┼────────────────────┴────┘│ │
38 │'a'│'b'│'c'│' '││NUL│ │ after valid range │
39 ├───┴───┴───┴───┴┴───┴─────────────────────────┐│ │
40 │ 'buf' (type: 'char[100]') ││ │
41 └──────────────────────────────────────────────┘└────────────────────────────────────┘
42 ├──────────────────────┬───────────────────────┤├─────────────────┬──────────────────┤
43 │ │
44 ╭─────────┴─────────╮ ╭──────────┴──────────╮
45 │capacity: 100 bytes│ │overflow of 350 bytes│
46 ╰───────────────────╯ ╰─────────────────────╯
47 { dg-end-multiline-output "" } */