1 /* PR middle-end/83373 - False positive reported by -Wstringop-overflow
2 { dg-do compile }
3 { dg-options "-O2 -Wstringop-overflow" } */
4
5 typedef __SIZE_TYPE__ size_t;
6
7 char buf[100];
8
9 void get_data (char*);
10
11 __attribute__ ((nonnull(1, 2)))
my_strcpy(char * dst,const char * src,size_t size)12 inline char* my_strcpy (char* dst, const char* src, size_t size)
13 {
14 size_t len = __builtin_strlen (src);
15 if (len < size)
16 __builtin_memcpy (dst, src, len + 1);
17 else
18 {
19 __builtin_memcpy (dst, src, size - 1); /* { dg-bogus "\\\[-Wstringop-oveflow]" } */
20 dst[size - 1] = '\0';
21 }
22
23 return dst;
24 }
25
test(void)26 void test(void)
27 {
28 char data[20] = "12345";
29
30 get_data (data);
31
32 my_strcpy (buf, data, sizeof buf);
33 }
34