diff options
author | Ian Lance Taylor <iant@golang.org> | 2023-06-26 09:57:21 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2023-06-26 09:57:21 -0700 |
commit | aa1e672b5d99102b03eb5fb9c51609c45f62bff7 (patch) | |
tree | 886212591b1c9d127eaaf234a4a2e22452ea384a /gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c | |
parent | 97e31a0a2a2d2273687fcdb4e5416aab1a2186e1 (diff) | |
parent | 3a39a31b8ae9c6465434aefa657f7fcc86f905c0 (diff) | |
download | gcc-devel/gccgo.zip gcc-devel/gccgo.tar.gz gcc-devel/gccgo.tar.bz2 |
Merge from trunk revision 3a39a31b8ae9c6465434aefa657f7fcc86f905c0.devel/gccgo
Diffstat (limited to 'gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c new file mode 100644 index 0000000..71f66ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c @@ -0,0 +1,55 @@ +/* { dg-additional-options "-fdiagnostics-show-path-depths" } */ +/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ +/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */ + +#include <stdint.h> + +int32_t arr[10]; + +void int_arr_write_element_after_end_off_by_one(int32_t x) +{ + arr[10] = x; /* { dg-line line } */ +} +/* { dg-warning "buffer overflow" "warning" { target *-*-* } line } */ +/* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } line } */ + + +/* { dg-begin-multiline-output "" } + arr[10] = x; + ~~~~~~~~^~~ + event 1 (depth 0) + | + | int32_t arr[10]; + | ^~~ + | | + | (1) capacity: 40 bytes + | + +--> 'int_arr_write_element_after_end_off_by_one': event 2 (depth 1) + | + | arr[10] = x; + | ~~~~~~~~^~~ + | | + | (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40 + | + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ┌────────────────────────────────┐ + │write from 'x' (type: 'int32_t')│ + └────────────────────────────────┘ + │ + │ + v + ┌────────┬─────────────────┬─────────┐┌────────────────────────────────┐ + │ [0] │ ... │ [9] ││ │ + ├────────┴─────────────────┴─────────┤│ after valid range │ + │ 'arr' (type: 'int32_t[10]') ││ │ + └────────────────────────────────────┘└────────────────────────────────┘ + ├─────────────────┬──────────────────┤├───────────────┬────────────────┤ + │ │ + ╭─────────┴────────╮ ╭─────────┴─────────╮ + │capacity: 40 bytes│ │overflow of 4 bytes│ + ╰──────────────────╯ ╰───────────────────╯ + + { dg-end-multiline-output "" } */ |