1 /* PR middle-end/88771 - Misleading -Werror=array-bounds error
2    Verify that the warning issued for calls to "bounded" string
3    functions when -Wstringop-overflow is disabled is -Warray-bounds
4    with the right wording.
5    { dg-do compile }
6    { dg-options "-O2 -Wall -Wno-stringop-overflow -Wno-stringop-overread" } */
7 
8 #define PTRDIFF_MAX   __PTRDIFF_MAX__
9 #define SIZE_MAX      __SIZE_MAX__
10 
11 typedef __SIZE_TYPE__ size_t;
12 
13 extern void* memcpy (void*, const void*, size_t);
14 extern void* memmove (void*, const void*, size_t);
15 extern void* memset (void*, int, size_t);
16 
17 extern char* stpncpy (char*, const char*, size_t);
18 
19 extern char* strncat (char*, const char*, size_t);
20 extern char* strncpy (char*, const char*, size_t);
21 
22 extern char* strndup (const char*, size_t);
23 
24 extern int strncmp (const char*, const char*, size_t);
25 extern int strncasecmp (const char*, const char*, size_t);
26 
27 extern size_t strnlen (const char*, size_t);
28 
29 extern char *d;
30 extern const char *s;
31 
32 
test_memcpy(void)33 void test_memcpy (void)
34 {
35   memcpy (d, s, SIZE_MAX);        /* { dg-warning ".memcpy. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
36 }
37 
test_memmove(void)38 void test_memmove (void)
39 {
40   memmove (d, s, SIZE_MAX - 1);   /* { dg-warning ".memmove. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
41 }
42 
test_memset(void)43 void test_memset (void)
44 {
45   memset (d, 0, SIZE_MAX - 2);    /* { dg-warning ".memset. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
46 }
47 
48 
test_stpncpy(void)49 char* test_stpncpy (void)
50 {
51   return stpncpy (d, s, SIZE_MAX - 4);   /* { dg-warning ".stpncpy. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
52 }
53 
54 
test_strncat(void)55 void test_strncat (void)
56 {
57   strncat (d, s, SIZE_MAX - 3);   /* { dg-warning ".strncat. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
58 }
59 
test_strncpy(void)60 void test_strncpy (void)
61 {
62   strncpy (d, s, SIZE_MAX - 4);   /* { dg-warning ".strncpy. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
63 }
64 
test_strndup(void)65 char* test_strndup (void)
66 {
67   return strndup (s, SIZE_MAX - 5);   /* { dg-warning ".strndup. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" "bug" { xfail *-*-* } } */
68 }
69 
test_strnlen(void)70 size_t test_strnlen (void)
71 {
72   return strnlen (s, SIZE_MAX - 6);   /* { dg-warning ".strnlen. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" "bug" { xfail *-*-* } } */
73 }
74