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