Debian Codegraph @

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

raw
1 /* { dg-additional-options "-fdiagnostics-show-path-depths" } */
2 /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
3 /* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
4
5 #include <stdint.h>
6
7 int32_t arr[10];
8
9 void int_arr_write_element_after_end_off_by_one(int32_t x)
10 {
11 arr[10] = x; /* { dg-line line } */
12 }
13 /* { dg-warning "buffer overflow" "warning" { target *-*-* } line } */
14 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } line } */
15
16
17 /* { dg-begin-multiline-output "" }
18 arr[10] = x;
19 ~~~~~~~~^~~
20 event 1 (depth 0)
21 │
22 │ int32_t arr[10];
23 │ ^~~
24 │ |
25 │ (1) capacity: 40 bytes
26 │
27 └──> 'int_arr_write_element_after_end_off_by_one': event 2 (depth 1)
28 │
29 │ arr[10] = x;
30 │ ~~~~~~~~^~~
31 │ |
32 │ (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
33 │
34 { dg-end-multiline-output "" } */
35
36 /* { dg-begin-multiline-output "" }
37
38 ┌────────────────────────────────┐
39 │write from 'x' (type: 'int32_t')│
40 └────────────────────────────────┘
41 │
42 │
43 v
44 ┌────────┬─────────────────┬─────────┐┌────────────────────────────────┐
45 │ [0] │ ... │ [9] ││ │
46 ├────────┴─────────────────┴─────────┤│ after valid range │
47 │ 'arr' (type: 'int32_t[10]') ││ │
48 └────────────────────────────────────┘└────────────────────────────────┘
49 ├─────────────────┬──────────────────┤├───────────────┬────────────────┤
50 │ │
51 ╭─────────┴────────╮ ╭─────────┴─────────╮
52 │capacity: 40 bytes│ │overflow of 4 bytes│
53 ╰──────────────────╯ ╰───────────────────╯
54
55 { dg-end-multiline-output "" } */