summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-overflow-5.c
blob: 4abce01b5f8f2a189cc8177273a9f49db8f1bc05 (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
54
55
56
57
58
/* PR tree-optimization/85259 - Missing -Wstringop-overflow= since r256683
   { dg-do compile }
   { dg-options "-O2 -Wstringop-overflow" } */

extern char* strcpy (char*, const char*);
extern char* strcat (char*, const char*);

char a1[1];
char a2[2];
char a3[3];
char a4[4];
char a5[5];
char a6[6];
char a7[7];
char a8[8];

/* Verify that at least one instance of -Wstringop-overflow is issued
   for each pair of strcpy/strcat calls.  */

void test_strcpy_strcat_1 (void)
{
  strcpy (a1, "1"), strcat (a1, "2");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_2 (void)
{
  strcpy (a2, "12"), strcat (a2, "3");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_3 (void)
{
  strcpy (a3, "123"), strcat (a3, "4");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_4 (void)
{
  strcpy (a4, "1234"), strcat (a4, "5");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_5 (void)
{
  strcpy (a5, "12345"), strcat (a5, "6");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_6 (void)
{
  strcpy (a6, "123456"), strcat (a6, "7");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_7 (void)
{
  strcpy (a7, "1234567"), strcat (a7, "8");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}

void test_strcpy_strcat_8 (void)
{
  strcpy (a8, "12345678"), strcat (a8, "9");   /* { dg-warning "\\\[-Wstringop-overflow=]" } */
}