]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Wstringop-overflow-29.c
1 /* PR middle-end/91582 - missing heap overflow detection for strcpy
2 Verify calls via function pointers.
4 { dg-options "-O2 -Wall -Wno-array-bounds -ftrack-macro-expansion=0" } */
6 typedef __attribute__ ((alloc_size (1))) char* allocfn_t (unsigned);
8 extern allocfn_t allocfn
;
12 void direct_call (void)
14 char *q
= allocfn (0); // { dg-message "object of size 0 allocated by 'allocfn'" "note" }
15 q
[0] = 0; // { dg-warning "\\\[-Wstringop-overflow" }
20 void local_ptr_call (void)
22 allocfn_t
*ptr
= allocfn
;
23 char *q
= ptr (1); // { dg-message "at offset -1 into destination object of size 1 allocated by 'allocfn'" "note" }
25 q
[-1] = 0; // { dg-warning "\\\[-Wstringop-overflow" }
30 void global_ptr_call (void)
32 extern allocfn_t
*ptralloc
;
34 allocfn_t
*ptr
= ptralloc
;
35 char *q
= ptr (2); // { dg-message "at offset 3 into destination object of size 2 allocated by 'ptralloc'" "note" }
38 q
[3] = 3; // { dg-warning "\\\[-Wstringop-overflow" }
42 void global_ptr_array_call (void)
44 extern allocfn_t
* (arralloc
[]);
46 allocfn_t
*ptr
= arralloc
[0];
47 char *q
= ptr (2); // { dg-message "at offset 3 into destination object of size 2 allocated by 'ptr'" "note" }
50 q
[3] = 3; // { dg-warning "\\\[-Wstringop-overflow" }
55 struct S
{ allocfn_t
*ptralloc
; };
57 void member_ptr_call (struct S
*p
)
59 char *q
= p
->ptralloc (3); // { dg-message "at offset 5 into destination object of size 3 allocated by 'ptralloc'" "note" }
63 q
[5] = 0; // { dg-warning "\\\[-Wstringop-overflow" }