On Sun, Jul 22, 2018 at 04:47:45PM -0600, Martin Sebor wrote:
> > No, I mean something like:
> > 
> > $ cat y.c
> > const char a[2][3] = { "1234", "xyz" };
> > char b[6];
> > 
> > int main ()
> > {
> >    __builtin_memcpy(b, a, 4);
> >    __builtin_memset(b + 4, 'a', 2);
> >    __builtin_printf("%.6s\n", b);
> > }
> > $ gcc y.c
> > y.c:1:24: warning: initializer-string for array of chars is too long
> >   const char a[2][3] = { "1234", "xyz" };
> >                          ^~~~~~
> > y.c:1:24: note: (near initialization for 'a[0]')
> > $ ./a.out
> > 1234aa
> > 
> > but expected would be "123xaa".
> 
> Hmm.  I assumed this was undefined in C but after double
> checking I'm not sure.  If it's in fact valid and the excess
> elements are required to be ignored I'll of course fix it in
> a subsequent patch.  Let me find out.

If we just warn about the initializer and treat it some way, an optimization
should not change how the initializer is treated.
The memcpy and memset themselves must be valid and they should just copy
whatever is in the initializer without optimizations.

        Jakub

Reply via email to