1 /* Verify that calls to strcpy to write to an element of an array of pointers
2 are not diagnosed (due to mistakenly using the size of the array as that
3 of the destination).
4 { dg-do compile }
5 { dg-options "-O2 -Wall" } */
6
7 typedef char A1[1];
8 typedef char A2[2];
9 typedef char A3[3];
10 typedef char A4[4];
11 typedef char A5[5];
12 typedef char A6[6];
13 typedef char A7[7];
14 typedef char A8[8];
15 typedef char A9[9];
16 typedef char A10[10];
17
18 A1* pa1[3];
19 A2* pa2[3];
20 A3* pa3[3];
21 A4* pa4[3];
22 A5* pa5[3];
23 A6* pa6[3];
24 A7* pa7[3];
25 A8* pa8[3];
26 A9* pa9[3];
27 A10* pa10[3];
28
29 void nowarn_a1_1 (int i)
30 {
31 __builtin_strcpy (*pa1[0], "");
32 __builtin_strcpy (*pa1[1], "");
33 __builtin_strcpy (*pa1[i], "");
34 }
35
36 void nowarn_a2_2 (int i)
37 {
38 __builtin_strcpy (*pa2[0], "1");
39 __builtin_strcpy (*pa2[1], "2");
40 __builtin_strcpy (*pa2[i], "3");
41 }
42
43 void nowarn_a3_3 (int i)
44 {
45 __builtin_strcpy (*pa3[0], "12");
46 __builtin_strcpy (*pa3[1], "23");
47 __builtin_strcpy (*pa3[i], "34");
48 }
49
50 void nowarn_a4_4 (int i)
51 {
52 __builtin_strcpy (*pa4[0], "123");
53 __builtin_strcpy (*pa4[1], "234");
54 __builtin_strcpy (*pa4[i], "345");
55 }
56
57 void nowarn_a5_5 (int i)
58 {
59 __builtin_strcpy (*pa5[0], "1234");
60 __builtin_strcpy (*pa5[1], "2345");
61 __builtin_strcpy (*pa5[i], "3456");
62 }
63
64 void nowarn_a6_6 (int i)
65 {
66 __builtin_strcpy (*pa6[0], "12345");
67 __builtin_strcpy (*pa6[1], "23456");
68 __builtin_strcpy (*pa6[1], "34567");
69 }
70
71 void nowarn_a10_10 (int i)
72 {
73 __builtin_strcpy (*pa10[0], "0123456789");
74 __builtin_strcpy (*pa10[1], "1234567890");
75 __builtin_strcpy (*pa10[i], "2345678909");
76 }