https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104964

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
All right, so this one is likely an invalid code:

cat x.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct bad_struct {
  struct
  {
    char s_str[1];
  } i;
};

struct good_struct
{
  char s_str[1];
};

ssize_t size = 30;

struct bad_struct *bad;
struct good_struct *good;

int main()
{
  good = (struct good_struct *)malloc (sizeof(struct good_struct) + size);
  char *str = good->s_str;
  strcpy (str, "sparta");

  bad = (struct bad_struct *)malloc (sizeof(struct bad_struct) + size);
  char *str2 = bad->i.s_str;
  strcpy (str2, "sparta");
  return 0;
}

It shows the difference in between wrapped struct and not wrapped one.

Reply via email to