1 /* Verify that writes at excessive offsets into declared or allocated
2 objects of unknown size are diagnosed.
4 { dg-options "-O2" } */
6 #define DIFF_MAX __PTRDIFF_MAX__
8 typedef __SIZE_TYPE__
size_t;
10 void* malloc (size_t);
11 void* memcpy (void*, const void*, size_t);
12 void* memset (void*, int, size_t);
17 void char_array_cst_off_cst_size (void)
19 extern char caxcc
[]; // { dg-message "at offset \\d+ into destination object 'caxcc'" }
22 size_t idx
= DIFF_MAX
- 3;
24 memset (p
+ idx
, 0, 3);
28 memset (p
+ idx
, 0, 3); // { dg-warning "writing 3 bytes into a region of size 2" }
32 memset (p
+ idx
, 0, 3); // { dg-warning "writing 3 bytes into a region of size 1" }
36 memset (p
+ idx
, 0, 3); // { dg-warning "writing 3 bytes into a region of size 0" }
41 void char_array_var_off_cst_size (size_t idx
)
43 /* The offset is a range with a very large lower bound and an upper
44 bound of DIFF_MAX. There's not point in also mentioning the latter
45 (it wouldn't make the note any more meaningful) so verify it only
46 mentions the lower bound. */
47 extern char caxvc
[]; // { dg-message "at offset \\d+ into destination object 'caxvc'" "note" }
51 if (idx
< DIFF_MAX
- 3)
54 memset (p
+ idx
, 0, 3);
57 memset (p
+ idx
, 0, 5); // { dg-warning "writing 5 bytes into a region of size 3" }
62 void char_array_var_off_var_size (size_t idx
, size_t n
)
64 extern char caxvv
[]; // { dg-message "at offset \\d+ into destination object 'caxvv'" "note" }
68 if (idx
< DIFF_MAX
- 3)
74 memset (p
+ idx
, 0, n
);
78 memset (p
+ idx
, 0, n
); // { dg-warning "writing between 4 and 8 bytes into a region of size 3" }
83 void alloc_array_var_off_cst_size (size_t n
, size_t idx
)
85 char *p
= malloc (n
); // { dg-message "at offset \\d+ into destination object" "note" }
87 if (idx
< DIFF_MAX
- 3)
90 memset (p
+ idx
, 0, 3);
93 memset (p
+ idx
, 0, 5); // { dg-warning "writing 5 bytes into a region of size 3" }
98 void int_array_cst_off_cst_size (void)
100 extern int iaxc
[]; // { dg-message "at offset \[1-9\]\[0-9\]+ into destination object 'iaxc'" }
103 size_t idx
= DIFF_MAX
/ sizeof *iaxc
;
105 memset (p
+ idx
, 0, 3);
108 memset (p
+ idx
, 0, 5); // { dg-warning "writing 5 bytes into a region of size 3" }
113 void* nowarn_anti_range_1 (char *p
, char *q
)
118 char *d
= __builtin_malloc (n
+ 1);
119 memcpy (d
, p
, n
+ 1); // { dg-bogus "-Wstringop-overflow" }