[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#392880: gcc-4.1: off-by-one error for string initialiser warnings



Jochen Voss <voss@debian.org> writes:

>     char string3[2] = "12";
>     char d[]="d";
>     char string4[2] = "123";
>     char e[]="e";

> Here 'string3' and 'string4' are unterminated, as can be seen from the
> program output at the end.  But only the initialiser for 'string4'
> gives a warning.  It would be nice if there would also be a warning
> for the case when the initialiser is just one byte too long (i.e. for
> 'string3' in my example).

The string3 initialiser is not too long, section 6.7.8/15 of the ISO C
standard states:

   "Successive characters of the character literal (including the
    terminating null character if there is room or if the array is of
    unknown size) initialize the elements of the array"

So string3 is correctly initialized with the two bytes '1' and '2' and
the terminating null is discarded.

-- 
Philip Martin



Reply to: