1 /* Verify that calling strndup and strnlen with an unknown bound isn't
2 diagnosed regardless of the size of the array and the type of the bound.
3 { dg-do compile }
4 { dg-options "-O -Wall" } */
5
6 #define NOIPA __attribute__ ((noipa))
7
8 typedef __SIZE_TYPE__ size_t;
9
10 extern char* strndup (const char*, size_t);
11 extern size_t strnlen (const char*, size_t);
12
13 /* TO DO: Passing a zero-length array to any function is almost certainly
14 a bug and should be diagnosed except perpaphs when the function also
15 takes a bound and its value is known to be zero. When this is
16 implemented this test will need to be adjusted. */
17 extern char a0[0];
18
19 extern char a1[1];
20
strndup_a0_si(short n)21 NOIPA char* strndup_a0_si (short n)
22 {
23 return strndup (a0, n);
24 }
25
strndup_a0_i(int n)26 NOIPA char* strndup_a0_i (int n)
27 {
28 return strndup (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
29 }
30
strndup_a0_li(long n)31 NOIPA char* strndup_a0_li (long n)
32 {
33 return strndup (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
34 }
35
strndup_a0_lli(long long n)36 NOIPA char* strndup_a0_lli (long long n)
37 {
38 return strndup (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
39 }
40
41
strndup_a0_usi(unsigned short n)42 NOIPA char* strndup_a0_usi (unsigned short n)
43 {
44 return strndup (a0, n);
45 }
46
strndup_a0_ui(unsigned n)47 NOIPA char* strndup_a0_ui (unsigned n)
48 {
49 return strndup (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
50 }
51
strndup_a0_uli(unsigned long n)52 NOIPA char* strndup_a0_uli (unsigned long n)
53 {
54 return strndup (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
55 }
56
strndup_a0_ulli(unsigned long long n)57 NOIPA char* strndup_a0_ulli (unsigned long long n)
58 {
59 return strndup (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
60 }
61
62
63
strndup_a1_si(short n)64 NOIPA char* strndup_a1_si (short n)
65 {
66 return strndup (a1, n);
67 }
68
strndup_a1_i(int n)69 NOIPA char* strndup_a1_i (int n)
70 {
71 return strndup (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
72 }
73
strndup_a1_li(long n)74 NOIPA char* strndup_a1_li (long n)
75 {
76 return strndup (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
77 }
78
strndup_a1_lli(long long n)79 NOIPA char* strndup_a1_lli (long long n)
80 {
81 return strndup (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
82 }
83
84
strndup_a1_usi(unsigned short n)85 NOIPA char* strndup_a1_usi (unsigned short n)
86 {
87 return strndup (a1, n);
88 }
89
strndup_a1_ui(unsigned n)90 NOIPA char* strndup_a1_ui (unsigned n)
91 {
92 return strndup (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
93 }
94
strndup_a1_uli(unsigned long n)95 NOIPA char* strndup_a1_uli (unsigned long n)
96 {
97 return strndup (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
98 }
99
strndup_a1_ulli(unsigned long long n)100 NOIPA char* strndup_a1_ulli (unsigned long long n)
101 {
102 return strndup (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
103 }
104
105
strnlen_a0_si(short n)106 NOIPA size_t strnlen_a0_si (short n)
107 {
108 return strnlen (a0, n);
109 }
110
strnlen_a0_i(int n)111 NOIPA size_t strnlen_a0_i (int n)
112 {
113 return strnlen (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
114 }
115
strnlen_a0_li(long n)116 NOIPA size_t strnlen_a0_li (long n)
117 {
118 return strnlen (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
119 }
120
strnlen_a0_lli(long long n)121 NOIPA size_t strnlen_a0_lli (long long n)
122 {
123 return strnlen (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
124 }
125
126
strnlen_a0_usi(unsigned short n)127 NOIPA size_t strnlen_a0_usi (unsigned short n)
128 {
129 return strnlen (a0, n);
130 }
131
strnlen_a0_ui(unsigned n)132 NOIPA size_t strnlen_a0_ui (unsigned n)
133 {
134 return strnlen (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
135 }
136
strnlen_a0_uli(unsigned long n)137 NOIPA size_t strnlen_a0_uli (unsigned long n)
138 {
139 return strnlen (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
140 }
141
strnlen_a0_ulli(unsigned long long n)142 NOIPA size_t strnlen_a0_ulli (unsigned long long n)
143 {
144 return strnlen (a0, n); // { dg-bogus "\\\[-Wstringop-overread" }
145 }
146
147
148
strnlen_a1_si(short n)149 NOIPA size_t strnlen_a1_si (short n)
150 {
151 return strnlen (a1, n);
152 }
153
strnlen_a1_i(int n)154 NOIPA size_t strnlen_a1_i (int n)
155 {
156 return strnlen (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
157 }
158
strnlen_a1_li(long n)159 NOIPA size_t strnlen_a1_li (long n)
160 {
161 return strnlen (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
162 }
163
strnlen_a1_lli(long long n)164 NOIPA size_t strnlen_a1_lli (long long n)
165 {
166 return strnlen (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
167 }
168
169
strnlen_a1_usi(unsigned short n)170 NOIPA size_t strnlen_a1_usi (unsigned short n)
171 {
172 return strnlen (a1, n);
173 }
174
strnlen_a1_ui(unsigned n)175 NOIPA size_t strnlen_a1_ui (unsigned n)
176 {
177 return strnlen (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
178 }
179
strnlen_a1_uli(unsigned long n)180 NOIPA size_t strnlen_a1_uli (unsigned long n)
181 {
182 return strnlen (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
183 }
184
strnlen_a1_ulli(unsigned long long n)185 NOIPA size_t strnlen_a1_ulli (unsigned long long n)
186 {
187 return strnlen (a1, n); // { dg-bogus "\\\[-Wstringop-overread" }
188 }
189