This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix wrong code with truncated string literals (PR 86711/86714)
- From: Jeff Law <law at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Bernd Edlinger <bernd dot edlinger at hotmail dot de>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Tue, 14 Aug 2018 23:37:16 -0600
- Subject: Re: [PATCH] Fix wrong code with truncated string literals (PR 86711/86714)
- References: <DB6PR0701MB266438272BCFD277C6600399E4280@DB6PR0701MB2664.eurprd07.prod.outlook.com> <f6300126-1ebf-dd86-ed91-507b0770b495@gmail.com> <AM5PR0701MB2657173012DF86883B5B4E39E42F0@AM5PR0701MB2657.eurprd07.prod.outlook.com> <f301b52c-df0d-0a10-7ce1-940139020b91@gmail.com> <AM5PR0701MB2657F4C71E034EE9EFDCB3D6E42F0@AM5PR0701MB2657.eurprd07.prod.outlook.com> <53ead905-b404-c0eb-8f03-5865bd786cf1@gmail.com> <20180731063350.GB17988@tucnak> <15e1ffe8-96e0-9c98-622d-4f8ea46d3c3b@redhat.com> <20180803212821.GW17988@tucnak>
On 08/03/2018 03:28 PM, Jakub Jelinek wrote:
> On Fri, Aug 03, 2018 at 03:16:41PM -0600, Jeff Law wrote:
>> On 07/31/2018 12:33 AM, Jakub Jelinek wrote:
>>> On Mon, Jul 30, 2018 at 10:01:38PM -0600, Martin Sebor wrote:
>>>>> We do not want to change what is currently accepted by the
>>>>> front end. period.
>>>>
>>>> On whose behalf are you making such categorical statements?
>>>> It was Jakub and Richard's suggestion in bug 86714 to reject
>>>> the undefined excessive initializers and I happen to like
>>>> the idea. I don't recall anyone making a decision about what
>>>
>>> It was not my suggestion and it is already rejected with -pedantic-errors,
>>> which is all that is needed, reject it in pedantic mode.
>>> Otherwise there is a warning emitted by default which is enough.
>> But I think that's a mistake. I think a hard error at this point is
>> warranted and the safest thing to do.
>
> The normal behavior when it isn't an error is that the initializer is
> truncated. That is what happens if I use
> struct S { char a[4]; };
> struct S r = { "abc" };
> struct S s = { "abcd" };
> struct S t = { "abcde" };
>
> C says that in the s.a initializer is actually just 'a', 'b',
> 'c', 'd' rather than 'a', 'b', 'c', 'd', '\0', so there is a silent
> truncation in the language naturally, so the extension that truncates even
> more with a warning enabled by default is IMHO natural and doesn't need to
> be more pedantic. We've always truncated, so there should be no surprises.
I wasn't aware C mandated a behavior here. With that in mind I think we
truncate per the C semantics and get on with our lives :-)
Jeff