| 1 |
/* PR middle-end/78138 - missing warnings on buffer overflow with non-constant |
| 2 |
source length |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wformat-overflow" } */ |
| 5 |
|
| 6 |
char d [5]; |
| 7 |
|
| 8 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 9 |
|
| 10 |
void* memcpy (void*, const void*, size_t); |
| 11 |
extern char* strcpy (char*, const char*); |
| 12 |
|
| 13 |
void f (int i, int j) |
| 14 |
{ |
| 15 |
strcpy (d, j ? "12345" : "123456"); /* { dg-warning ".strcpy. writing between 6 and 7 bytes into a region of size 5 " } */ |
| 16 |
} |
| 17 |
|
| 18 |
void g (void *p) |
| 19 |
{ |
| 20 |
extern unsigned n; |
| 21 |
if (n < 17 || 32 < n) n = 7; |
| 22 |
|
| 23 |
memcpy (d, p, n); /* { dg-warning ".memcpy. writing between 7 and 32 bytes into a region of size 5" } */ |
| 24 |
}; |