This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFA] Avoid ubsan complaint in BFD
- From: Tom Tromey <tom at tromey dot com>
- To: John Darrington <john at darrington dot wattle dot id dot au>
- Cc: Tom Tromey <tom at tromey dot com>, binutils at sourceware dot org
- Date: Fri, 20 Jul 2018 11:48:43 -0600
- Subject: Re: [RFA] Avoid ubsan complaint in BFD
- References: <20180720155241.20974-1-tom@tromey.com> <20180720171202.GA14025@jocasta.intra>
>>>>> "John" == John Darrington <john@darrington.wattle.id.au> writes:
John> My personal opinion is that if tools don't understand the standard(s)
John> properly, then it's bad form to pander to them just for the sake of
John> shutting them up.
I'm not really that great at reading the C standard, but I think it says
that passing NULL to memcpy is undefined behavior.
I did some research and came up with this.
Reading from n1570.pdf, section 7.24.1 "String function conventions":
Where an argument declared as size_t n specifies the length of the
array for a function, n can have the value zero on a call to that
function. Unless explicitly stated otherwise in the description of
a particular function in this subclause, pointer arguments on such a
call shall still have valid values, as described in 7.1.4. On such
a call, a function that locates a character finds no occurrence, a
function that compares two character sequences returns zero, and a
function that copies characters copies zero characters.
This applies to memcpy, which is defined in section 7.24.2.1.
And, there is no clause there saying that NULL is allowed.
glibc seems to agree with this, as it marks these arguments __nonnull.
If you think this is in error, I'd appreciate learning why.
thanks,
Tom