| 1 |
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */ |
| 2 |
/* { dg-skip-if "" { powerpc-ibm-aix* } } */ |
| 3 |
|
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
void |
| 7 |
test_non_ascii () |
| 8 |
{ |
| 9 |
char buf[9]; |
| 10 |
strcpy (buf, "Liberté\n"); /* { dg-warning "stack-based buffer overflow" } */ |
| 11 |
/* { dg-warning "'__builtin_memcpy' writing 10 bytes into a region of size 9 overflows the destination" "" { target *-*-* } .-1 } */ |
| 12 |
} |
| 13 |
|
| 14 |
/* Example of non-ASCII UTF-8 that's short enough to fully quote, whilst |
| 15 |
containing control characters. */ |
| 16 |
|
| 17 |
/* { dg-begin-multiline-output "" } |
| 18 |
|
| 19 |
┌──────┬──────┬──────┬──────┬──────┬──────┬────┬────┬──────┐┌─────────────────┐ |
| 20 |
│ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │[6] │[7] │ [8] ││ [9] │ |
| 21 |
├──────┼──────┼──────┼──────┼──────┼──────┼────┼────┼──────┤├─────────────────┤ |
| 22 |
│ 0x4c │ 0x69 │ 0x62 │ 0x65 │ 0x72 │ 0x74 │0xc3│0xa9│ 0x0a ││ 0x00 │ |
| 23 |
├──────┼──────┼──────┼──────┼──────┼──────┼────┴────┼──────┤├─────────────────┤ |
| 24 |
│U+004c│U+0069│U+0062│U+0065│U+0072│U+0074│ U+00e9 │U+000a││ U+0000 │ |
| 25 |
├──────┼──────┼──────┼──────┼──────┼──────┼─────────┼──────┤├─────────────────┤ |
| 26 |
│ L │ i │ b │ e │ r │ t │ é │ ││ NUL │ |
| 27 |
├──────┴──────┴──────┴──────┴──────┴──────┴─────────┴──────┴┴─────────────────┤ |
| 28 |
│ string literal (type: 'char[10]') │ |
| 29 |
└─────────────────────────────────────────────────────────────────────────────┘ |
| 30 |
│ │ │ │ │ │ │ │ │ │ |
| 31 |
│ │ │ │ │ │ │ │ │ │ |
| 32 |
v v v v v v v v v v |
| 33 |
┌──────┬────────────────────────────────────────────┬──────┐┌─────────────────┐ |
| 34 |
│ [0] │ ... │ [8] ││ │ |
| 35 |
├──────┴────────────────────────────────────────────┴──────┤│after valid range│ |
| 36 |
│ 'buf' (type: 'char[9]') ││ │ |
| 37 |
└──────────────────────────────────────────────────────────┘└─────────────────┘ |
| 38 |
├────────────────────────────┬─────────────────────────────┤├────────┬────────┤ |
| 39 |
│ │ |
| 40 |
╭────────┴────────╮ ╭─────────┴────────╮ |
| 41 |
│capacity: 9 bytes│ │overflow of 1 byte│ |
| 42 |
╰─────────────────╯ ╰──────────────────╯ |
| 43 |
|
| 44 |
{ dg-end-multiline-output "" } */ |