| 1 |
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */ |
| 2 |
|
| 3 |
#include <string.h> |
| 4 |
#include "analyzer-decls.h" |
| 5 |
|
| 6 |
char *test_fixed_size_heap_2_invalid (void) |
| 7 |
{ |
| 8 |
char str[] = "abc"; |
| 9 |
char *p = __builtin_malloc (strlen (str)); /* { dg-message "\\(1\\) capacity: 3 bytes" } */ |
| 10 |
if (!p) |
| 11 |
return NULL; |
| 12 |
strcpy (p, str); /* { dg-warning "heap-based buffer overflow" } */ |
| 13 |
return p; |
| 14 |
} |
| 15 |
|
| 16 |
/* { dg-begin-multiline-output "" } |
| 17 |
┌──────────────────────────────────────────────────────────────────────┐ |
| 18 |
│ write of 4 bytes │ |
| 19 |
└──────────────────────────────────────────────────────────────────────┘ |
| 20 |
│ │ |
| 21 |
│ │ |
| 22 |
v v |
| 23 |
┌───────────────────────────────────────────────────┐┌─────────────────┐ |
| 24 |
│ buffer allocated on heap at (1) ││after valid range│ |
| 25 |
└───────────────────────────────────────────────────┘└─────────────────┘ |
| 26 |
├─────────────────────────┬─────────────────────────┤├────────┬────────┤ |
| 27 |
│ │ |
| 28 |
╭────────┴────────╮ ╭─────────┴────────╮ |
| 29 |
│capacity: 3 bytes│ │overflow of 1 byte│ |
| 30 |
╰─────────────────╯ ╰──────────────────╯ |
| 31 |
{ dg-end-multiline-output "" } */ |