[RFA] Avoid ubsan complaint in BFD
Tom Tromey
tom@tromey.com
Fri Jul 20 17:57:00 GMT 2018
>>>>> "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
More information about the Binutils
mailing list