| 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_string_with_control_chars () |
| 8 |
{ |
| 9 |
char buf[8]; |
| 10 |
strcpy (buf, "\tone\n\ttwo\n"); /* { dg-warning "stack-based buffer overflow" } */ |
| 11 |
/* { dg-warning "'__builtin_memcpy' writing 11 bytes into a region of size 8 overflows the destination" "" { target *-*-* } .-1 } */ |
| 12 |
} |
| 13 |
|
| 14 |
/* { dg-begin-multiline-output "" } |
| 15 |
|
| 16 |
┌──────┬──────┬──────┬─────┬─────┬─────┬─────┬─────┐┌─────┬─────┬──────┐ |
| 17 |
│ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │ [6] │ [7] ││ [8] │ [9] │ [10] │ |
| 18 |
├──────┼──────┼──────┼─────┼─────┼─────┼─────┼─────┤├─────┼─────┼──────┤ |
| 19 |
│ 0x09 │ 'o' │ 'n' │ 'e' │0x0a │0x09 │ 't' │ 'w' ││ 'o' │0x0a │ NUL │ |
| 20 |
├──────┴──────┴──────┴─────┴─────┴─────┴─────┴─────┴┴─────┴─────┴──────┤ |
| 21 |
│ string literal (type: 'char[11]') │ |
| 22 |
└──────────────────────────────────────────────────────────────────────┘ |
| 23 |
│ │ │ │ │ │ │ │ │ │ │ |
| 24 |
│ │ │ │ │ │ │ │ │ │ │ |
| 25 |
v v v v v v v v v v v |
| 26 |
┌──────┬─────────────────────────────────────┬─────┐┌──────────────────┐ |
| 27 |
│ [0] │ ... │ [7] ││ │ |
| 28 |
├──────┴─────────────────────────────────────┴─────┤│after valid range │ |
| 29 |
│ 'buf' (type: 'char[8]') ││ │ |
| 30 |
└──────────────────────────────────────────────────┘└──────────────────┘ |
| 31 |
├────────────────────────┬─────────────────────────┤├────────┬─────────┤ |
| 32 |
│ │ |
| 33 |
╭────────┴────────╮ ╭─────────┴─────────╮ |
| 34 |
│capacity: 8 bytes│ │overflow of 3 bytes│ |
| 35 |
╰─────────────────╯ ╰───────────────────╯ |
| 36 |
|
| 37 |
{ dg-end-multiline-output "" } */ |