1 /* Verify -Wstringop-overflow a with destination pointer pointing either
2 before the beginning or past the end of an object.
4 { dg-options "-O -Wall -Wno-array-bounds -Wno-restrict" } */
6 typedef __SIZE_TYPE__
size_t;
8 char* strcpy (char *, const char *);
15 void cpy_si_1_max (int i
, const char *s
)
18 d
= strcpy (a
+ i
, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" }
19 d
= strcpy (a
+ i
+ 1, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" }
22 void cpy_ui_1_max (unsigned i
, const char *s
)
25 d
= strcpy (a
+ i
, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" }
26 d
= strcpy (a
+ i
+ 1, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { xfail { ! lp64 } } }
29 void cpy_sl_1_max (long i
, const char *s
)
32 d
= strcpy (a
+ i
, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
33 d
= strcpy (a
+ i
+ 1, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
36 void cpy_ul_1_max (unsigned long i
, const char *s
)
40 d
= strcpy (a
+ i
, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
42 /* Because of integer wraparound the offset's range is [1, 0] so
43 the overflow isn't diagnosed (yet). */
44 d
= strcpy (a
+ i
+ 1, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { xfail *-*-* } }
48 void cpy_si_min_m1 (int i
, const char *s
)
51 d
= strcpy (a
+ i
- 1, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" }
52 d
= strcpy (a
+ i
, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" }
53 d
= strcpy (a
+ i
+ 2, s
);
56 void cpy_sl_min_m1 (long i
, const char *s
)
59 d
= strcpy (a
+ i
- 1, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
60 d
= strcpy (a
+ i
, s
); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
61 d
= strcpy (a
+ i
+ 2, s
);