aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-overflow-33.c
blob: d4f7956c42db7f706b871fe5c381e9ad974b2e6c (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
/* PR middle-end/82456 - missing -Wstringop-overflow on strcpy reading past
   the end of an array
   { dg-do compile }
   { dg-options "-O2 -Wall" } */

void fcst (char *d)
{
  char a[2] = "0";

  __builtin_strcpy (d, a + 3);    // { dg-warning "\\\[-W(array-bounds|stringop-overread)" }
}

void frng (char *d, int i)
{
  char a[2] = "0";

  if (i < 3)
    i = 3;

  __builtin_strcpy (d, a + i);    // { dg-warning "\\\[-W(array-bounds|stringop-overread)" }
}

void gcst (char *d)
{
  char a[2] = "0";

  __builtin_strcpy (d, a + 2);    // { dg-warning "\\\[-W(array-bounds|stringop-overread)" }
}

void grng (char *d, int i)
{
  char a[2] = "0";

  if (i < 2)
    i = 2;

  __builtin_strcpy (d, a + i);    // { dg-warning "\\\[-W(array-bounds|stringop-overread)" }
}

/* { dg-prune-output "-Wuninitialized" } */