diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c new file mode 100644 index 0000000..064f3fa --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c @@ -0,0 +1,45 @@ +/* The multiline output assumes sizeof(size_t) == 8. + { dg-require-effective-target lp64 } */ + +/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */ + +#include <stdlib.h> +#include <string.h> +#include <stdint.h> + +struct str { + size_t len; + char data[]; +}; + +struct str * +make_str_badly (const char *src) +{ + size_t len = strlen(src); + struct str *str = malloc(sizeof(str) + len); /* { dg-message "\\(1\\) capacity: 'len \\+ 8' bytes" } */ + if (!str) + return NULL; + str->len = len; + memcpy(str->data, src, len); + str->data[len] = '\0'; /* { dg-warning "heap-based buffer overflow" } */ + return str; +} + +/* { dg-begin-multiline-output "" } + + ┌──────────────────────────────────┐ + │ write of '(char) 0' │ + └──────────────────────────────────┘ + │ + │ + v + ┌──────────────────────────────────┐┌──────────────────────────────────┐ + │ buffer allocated on heap at (1) ││ after valid range │ + └──────────────────────────────────┘└──────────────────────────────────┘ + ├────────────────┬─────────────────┤├────────────────┬─────────────────┤ + │ │ + ╭────────────┴────────────╮ ╭─────────┴────────╮ + │capacity: 'len + 8' bytes│ │overflow of 1 byte│ + ╰─────────────────────────╯ ╰──────────────────╯ + + { dg-end-multiline-output "" } */ |