| 1 |
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */ |
| 2 |
/* { dg-skip-if "" { powerpc-ibm-aix* } } */ |
| 3 |
|
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
#define LOREM_IPSUM \ |
| 7 |
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod" \ |
| 8 |
" tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" \ |
| 9 |
" veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" \ |
| 10 |
" commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" \ |
| 11 |
" velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" \ |
| 12 |
" occaecat cupidatat non proident, sunt in culpa qui officia deserunt" \ |
| 13 |
" mollit anim id est laborum." |
| 14 |
|
| 15 |
void test (void) |
| 16 |
{ |
| 17 |
char buf[500]; |
| 18 |
strcpy (buf, LOREM_IPSUM); |
| 19 |
strcat (buf, LOREM_IPSUM); /* { dg-warning "stack-based buffer overflow" } */ |
| 20 |
} |
| 21 |
|
| 22 |
/* { dg-begin-multiline-output "" } |
| 23 |
|
| 24 |
┌─────┬───┬───┬───┬───┬───┬────────┬─────┬─────┬─────┬─────┬─────┬─────┐ |
| 25 |
│ [0] │[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│ |
| 26 |
├─────┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤ |
| 27 |
│ 'L' │'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │ |
| 28 |
├─────┴───┴───┴───┴───┴───┴────────┴─────┴─────┴─────┴─────┴─────┴─────┤ |
| 29 |
│ string literal (type: 'char[446]') │ |
| 30 |
└──────────────────────────────────────────────────────────────────────┘ |
| 31 |
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ |
| 32 |
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ |
| 33 |
v v v v v v v v v v v v v v v |
| 34 |
┌───┬────────────────────────────────────────────┬─────┬────────────────────┬─────┐┌────────────────────────────────────┐ |
| 35 |
│[0]│ ... │[445]│ ... │[499]││ │ |
| 36 |
├───┼───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬┼─────┼────────────────────┴─────┘│ │ |
| 37 |
│'L'│'o'│'r'│'e'│'m'│' '│...│'o'│'r'│'u'│'m'│'.'││ NUL │ │ after valid range │ |
| 38 |
├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴┴─────┴──────────────────────────┐│ │ |
| 39 |
│ 'buf' (type: 'char[500]') ││ │ |
| 40 |
└─────────────────────────────────────────────────────────────────────────────────┘└────────────────────────────────────┘ |
| 41 |
├────────────────────────────────────────┬────────────────────────────────────────┤├─────────────────┬──────────────────┤ |
| 42 |
│ │ |
| 43 |
╭─────────┴─────────╮ ╭──────────┴──────────╮ |
| 44 |
│capacity: 500 bytes│ │overflow of 391 bytes│ |
| 45 |
╰───────────────────╯ ╰─────────────────────╯ |
| 46 |
|
| 47 |
{ dg-end-multiline-output "" { target c } } */ |
| 48 |
|
| 49 |
/* { dg-begin-multiline-output "" } |
| 50 |
|
| 51 |
┌─────┬───┬───┬───┬───┬───┬────────┬─────┬─────┬─────┬─────┬─────┬─────┐ |
| 52 |
│ [0] │[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│ |
| 53 |
├─────┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤ |
| 54 |
│ 'L' │'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │ |
| 55 |
├─────┴───┴───┴───┴───┴───┴────────┴─────┴─────┴─────┴─────┴─────┴─────┤ |
| 56 |
│ string literal (type: 'const char[446]') │ |
| 57 |
└──────────────────────────────────────────────────────────────────────┘ |
| 58 |
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ |
| 59 |
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ |
| 60 |
v v v v v v v v v v v v v v v |
| 61 |
┌───┬────────────────────────────────────────────┬─────┬────────────────────┬─────┐┌────────────────────────────────────┐ |
| 62 |
│[0]│ ... │[445]│ ... │[499]││ │ |
| 63 |
├───┼───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬┼─────┼────────────────────┴─────┘│ │ |
| 64 |
│'L'│'o'│'r'│'e'│'m'│' '│...│'o'│'r'│'u'│'m'│'.'││ NUL │ │ after valid range │ |
| 65 |
├───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴┴─────┴──────────────────────────┐│ │ |
| 66 |
│ 'char buf [500]' (type: 'char[500]') ││ │ |
| 67 |
└─────────────────────────────────────────────────────────────────────────────────┘└────────────────────────────────────┘ |
| 68 |
├────────────────────────────────────────┬────────────────────────────────────────┤├─────────────────┬──────────────────┤ |
| 69 |
│ │ |
| 70 |
╭─────────┴─────────╮ ╭──────────┴──────────╮ |
| 71 |
│capacity: 500 bytes│ │overflow of 391 bytes│ |
| 72 |
╰───────────────────╯ ╰─────────────────────╯ |
| 73 |
|
| 74 |
{ dg-end-multiline-output "" { target c++ } } */ |