aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-12.c
blob: 3573750e57ab9b2a937389910b2c58a8b7a71d91 (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
44
45
46
47
48
49
50
51
52
53
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
/* { dg-require-effective-target alloca } */

#include <string.h>
#include <stdlib.h>
#include <stdint.h>

void test8 (size_t size, size_t offset)
{
  char src[size];
  char dst[size];
  memcpy (dst, src, size + offset); /* { dg-line test8 } */
  /* { dg-warning "over-read" "warning" { target *-*-* } test8 } */
  /* { dg-warning "overflow" "warning" { target *-*-* } test8 } */
}

/* { dg-begin-multiline-output "" }

  ┌──────────────────────────────────────────────────────────────────────┐
  │                    read of 'size + offset' bytes                     │
  └──────────────────────────────────────────────────────────────────────┘
                   ^                                   ^
                   │                                   │
                   │                                   │
  ┌──────────────────────────────────┐┌──────────────────────────────────┐
  │ buffer allocated on stack at (1) ││        after valid range         │
  └──────────────────────────────────┘└──────────────────────────────────┘
  ├────────────────┬─────────────────┤├────────────────┬─────────────────┤
                   │                                   │
         ╭─────────┴────────╮            ╭─────────────┴─────────────╮
         │size: 'size' bytes│            │over-read of 'offset' bytes│
         ╰──────────────────╯            ╰───────────────────────────╯

   { dg-end-multiline-output "" } */

/* { dg-begin-multiline-output "" }

  ┌──────────────────────────────────────────────────────────────────────┐
  │                    write of 'size + offset' bytes                    │
  └──────────────────────────────────────────────────────────────────────┘
                   │                                   │
                   │                                   │
                   v                                   v
  ┌──────────────────────────────────┐┌──────────────────────────────────┐
  │ buffer allocated on stack at (1) ││        after valid range         │
  └──────────────────────────────────┘└──────────────────────────────────┘
  ├────────────────┬─────────────────┤├────────────────┬─────────────────┤
                   │                                   │
       ╭───────────┴──────────╮          ╭─────────────┴────────────╮
       │capacity: 'size' bytes│          │overflow of 'offset' bytes│
       ╰──────────────────────╯          ╰──────────────────────────╯

   { dg-end-multiline-output "" } */