]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Wstringop-overflow-14.c
d23a248446bf9382c015a76cd8c48d7a29ec0847
1 /* Test to verify that past-the-end multibyte writes via lvalues of wider
2 types than char are diagnosed.
4 { dg-require-effective-target int32plus }
5 { dg-options "-O2 -Wall" } */
7 typedef __INT16_TYPE__
int16_t;
8 typedef __INT32_TYPE__
int32_t;
9 typedef __INT64_TYPE__
int64_t;
10 typedef __SIZE_TYPE__
size_t;
12 void* memcpy (void*, const void*, size_t);
13 char* strcpy (char*, const char*);
15 char a4
[4], a8
[8], a16
[16];
17 const char s4
[] = "1234";
18 const char t4
[] = "4321";
20 void test_memcpy_cond (int i
)
23 const char *q
= i
? s4
: t4
;
24 memcpy (p
, q
, 4); // { dg-warning "writing 4 bytes into a region of size 3" }
28 void test_int16 (void)
32 *(int16_t*)(p
+ 2) = 0; // { dg-warning "writing 2 bytes into a region of size 1" }
36 void test_int32 (void)
40 *(int32_t*)(p
+ 2) = 0; // { dg-warning "writing 4 bytes into a region of size 3" }
44 void test_int64 (void)
48 *(int64_t*)(p
+ 5) = 0; // { dg-warning "writing 8 bytes into a region of size 6" }