type = TYPE_MAIN_VARIANT (type);
if (TREE_CODE (type) == ARRAY_TYPE
- && !array_at_struct_end_p (dest))
+ && !array_at_struct_end_p (TREE_OPERAND (dest, 0)))
{
/* Return the constant size unless it's zero (that's a zero-length
array likely at the end of a struct). */
{
strncpy (p->a, s, sizeof p->a); /* { dg-warning "\\\[-Wstringop-truncation" } */
strncpy ((char*)p->b, s, sizeof p->b); /* { dg-warning "\\\[-Wstringop-truncation" } */
- strncpy ((char*)p->c, s, sizeof p->c); /* { dg-warning "\\\[-Wstringop-truncation" } */
+ strncpy ((char*)p->c, s, sizeof p->c); /* { dg-bogus "\\\[-Wstringop-truncation" } */
}
struct Pointers
{
strncpy ((char*)p->a, s, sizeof p->a); /* { dg-warning "\\\[-Wstringop-truncation" } */
strncpy ((char*)p->b, s, sizeof p->b); /* { dg-warning "\\\[-Wstringop-truncation" } */
- strncpy ((char*)p->c, s, sizeof p->c); /* { dg-warning "\\\[-Wstringop-truncation" } */
+ strncpy ((char*)p->c, s, sizeof p->c); /* { dg-bogus "\\\[-Wstringop-truncation" } */
}
struct ConstPointers
{
strncpy ((char*)p->a, s, sizeof p->a); /* { dg-warning "\\\[-Wstringop-truncation" } */
strncpy ((char*)p->b, s, sizeof p->b); /* { dg-warning "\\\[-Wstringop-truncation" } */
- strncpy ((char*)p->c, s, sizeof p->c); /* { dg-warning "\\\[-Wstringop-truncation" } */
+ strncpy ((char*)p->c, s, sizeof p->c); /* { dg-bogus "\\\[-Wstringop-truncation" } */
}
struct VolatilePointers
{
strncpy ((char*)p->a, s, sizeof p->a); /* { dg-warning "\\\[-Wstringop-truncation" } */
strncpy ((char*)p->b, s, sizeof p->b); /* { dg-warning "\\\[-Wstringop-truncation" } */
- strncpy ((char*)p->c, s, sizeof p->c); /* { dg-warning "\\\[-Wstringop-truncation" } */
+ strncpy ((char*)p->c, s, sizeof p->c); /* { dg-bogus "\\\[-Wstringop-truncation" } */
}
struct ConstVolatilePointers
--- /dev/null
+/* { dg-do compile }
+ { dg-options "-O2 -Wstringop-overflow" } */
+
+extern char* strchr (const char*, int);
+extern char* strcpy (char*, const char*);
+extern void* malloc (__SIZE_TYPE__);
+extern __SIZE_TYPE__ strlen (const char *);
+struct define_item {
+ int len;
+ char value[1];
+};
+
+struct define_item * foo(char *name)
+{
+ char * p;
+ char * value;
+ struct define_item * ptr;
+
+ p = strchr (name, '=');
+ if (1 && p) {
+ value = p+1;
+ } else
+ value = "1";
+
+ ptr = malloc(sizeof(struct define_item) + strlen(value));
+ strcpy(ptr->value, value); /* { dg-bogus "bytes into a region" } */
+ return ptr;
+}