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

--- Comment #1 from mikulas at artax dot karlin.mff.cuni.cz 2012-09-02 01:52:54 
UTC ---
Another specification violation:

section 6.7.2.1 paragraph 20 says that assignment of a structure with flexible
array member doesn't copy any of the array elements. In gcc it is buggy because
it copies some array elements.

Try this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct flexible {
        unsigned a;
        unsigned short b;
        unsigned char array[];
};

int main(void)
{
        struct flexible *f1, *f2;
        f1 = malloc(sizeof(struct flexible) + 3);
        f1->array[0] = 0;
        f1->array[1] = 0;
        f1->array[2] = 0;
        f2 = malloc(sizeof(struct flexible) + 3);
        f2->array[0] = 1;
        f2->array[1] = 1;
        f2->array[2] = 1;
        *f2 = *f1;
        printf("f2->array[0] == %d (should be 1)\n", f2->array[0]);
        printf("f2->array[1] == %d (should be 1)\n", f2->array[1]);
        printf("f2->array[2] == %d (should be 1)\n", f2->array[2]);
        return 0;
}

Reply via email to