This is the mail archive of the
mailing list for the GCC project.
Re: memset zero bytes at NULL - isolate-erroneous-paths
- From: Jeff Law <law at redhat dot com>
- To: Florian Weimer <fw at deneb dot enyo dot de>, Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: Dominic News <d dot newsgroups at googlemail dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sun, 17 Nov 2013 21:31:07 -0700
- Subject: Re: memset zero bytes at NULL - isolate-erroneous-paths
- Authentication-results: sourceware.org; auth=none
- References: <CALx3oLxLBCYez=jUiD7sLE-ynVHZ0Dr9QfX3QeLqCP-1p2p1nw at mail dot gmail dot com> <CAH6eHdSS9q-McGntA1+61TSe8EU_GVZ67RiFdLkr2APWVT7Evg at mail dot gmail dot com> <87d2lyn0u8 dot fsf at mid dot deneb dot enyo dot de>
On 11/17/13 15:02, Florian Weimer wrote:
No, it's C99 I think. There was a clarification which came in after C99
which clarified that even if the length is zero, the pointers must still
* Jonathan Wakely:
On 17 November 2013 18:25, Dominic News wrote:
In the following code (from xorg-server)
if (a == 0)
addr = 0;
memset(addr, '\0', a);
the path for a==0 is turned into a trap by -fisolate-erroneous-paths. (Is
calling memset like this undefined behaviour?)
Yes. 7.23.1 in the C standard says that even with a zero size the
pointer argument must be valid.
Is this new in C11? Does it apply to functions such as strnlen as well?
The language is such that unless there's an explicit exception for a
particular function, those rules always apply.