view gcc/testsuite/gcc.dg/Wstringop-overflow-4.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
line wrap: on
line source

/* { 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;
}