So I have these two structs. Only need to worry about these three variables; name_size, name and xattrs[0].
typedef struct dxattr {
    unsigned int name_size;        /* length of name string in bytes */
    unsigned int value_offset;     /* offset of value in value blocks */
    unsigned int value_size;       /* length of value string in bytes */
    char name[0];                  /* reference to the name string */
} dxattr_t;
typedef struct xcb {
    unsigned int value_blocks[5];  /* blocks for xattr values */
    unsigned int no_xattrs;            /* the number of xattrs in the block */
    unsigned int size;                 /* this is the end of the value list in bytes */
    dxattr_t xattrs[0];                /* then a list of xattr structs (names and value refs) */
} xcb_t;
First I update index 0 in xattrs
xcb_t *xcb = (xcb_t*)malloc( sizeof(xcb_t) );
xcb->xattrs[0].name_size = 5;
memcpy( xcb->xattrs[ 0 ].name, "keith", 5 );
xcb->xattrs[ 0 ].name[ 5 ] = 0; //null terminator
printf("xcb->xattrs[0].name = %s\n", xcb->xattrs[0].name );
printf("xcb->xattrs[0].name_size = %d\n", xcb->xattrs[0].name_size );
The output is;
xcb->xattrs[0].name = keith                                                                                             
xcb->xattrs[0].name_size = 5 
Then I try updating the 2nd index.
memcpy( xcb->xattrs[ 1 ].name, "david", 5 );
xcb->xattrs[ 1 ].name[ 5 ] = 0; //null terminator
printf("xcb->xattrs[0].name = %s\n", xcb->xattrs[0].name );
xcb->xattrs[1].name_size = 5;
printf("xcb->xattrs[0].name = %s\n", xcb->xattrs[0].name );
Immediately after updating the "name_size" variable, the "name" value in previous index gets erased.
xcb->xattrs[0].name = keith                                                                                             
xcb->xattrs[0].name = 
Any idea why this happens?
 
     
    