| 1 |
/* { dg-do compile } |
| 2 |
{ dg-options "-O2 -Wstringop-overflow" } */ |
| 3 |
|
| 4 |
extern char* strchr (const char*, int); |
| 5 |
extern char* strcpy (char*, const char*); |
| 6 |
extern void* malloc (__SIZE_TYPE__); |
| 7 |
extern __SIZE_TYPE__ strlen (const char *); |
| 8 |
struct define_item { |
| 9 |
int len; |
| 10 |
char value[1]; |
| 11 |
}; |
| 12 |
|
| 13 |
struct define_item * foo(char *name) |
| 14 |
{ |
| 15 |
char * p; |
| 16 |
char * value; |
| 17 |
struct define_item * ptr; |
| 18 |
|
| 19 |
p = strchr (name, '='); |
| 20 |
if (1 && p) { |
| 21 |
value = p+1; |
| 22 |
} else |
| 23 |
value = "1"; |
| 24 |
|
| 25 |
ptr = malloc(sizeof(struct define_item) + strlen(value)); |
| 26 |
strcpy(ptr->value, value); /* { dg-bogus "bytes into a region" } */ |
| 27 |
return ptr; |
| 28 |
} |