------- Comment #3 from rguenth at gcc dot gnu dot org  2010-01-21 11:34 -------
Or even
struct X {
    struct Y {
        char s[4];
    } y;
};

void * __attribute__((noinline,noclone))
myalloc (unsigned int sz)
{
  return __builtin_malloc (sz);
}

int main()
{
  struct X *p = myalloc (sizeof (struct Y)
                         + sizeof ("Hello World") + 1 - 4);
  struct Y *q = &p->y;
  __builtin___strcpy_chk (q->s, "Hello World",
                          __builtin_object_size (q->s, 1));
  return 0;
}

(warns)

vs.

struct X {
    struct Y {
        char s[4];
    } y;
};

void * __attribute__((noinline,noclone))
myalloc (unsigned int sz)
{
  return __builtin_malloc (sz);
}

int main()
{
  struct X *p = myalloc (sizeof (struct Y)
                         + sizeof ("Hello World") + 1 - 4);
  struct Y *q = (struct Y *)p;
  __builtin___strcpy_chk (q->s, "Hello World",
                          __builtin_object_size (q->s, 1));
  return 0;
}

(does not warn)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42821

Reply via email to