https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67535

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Steve Kargl from comment #4)
> It's undefined behavior to pass a NULL pointer into a function?

To a function that does not allow it?  Yes.

Citing the C standard:
7.21.2.1/2:
"The memcpy function copies n characters from the object pointed to by s2 into
the object pointed to by s1."
(NULL pointer does not point to any object).
7.1.4/1:
"If a function argument is
described as being an array, the pointer actually passed to the function shall
have a value
such that all address computations and accesses to objects (that would be valid
if the
pointer did point to the first element of such an array) are in fact valid."
7.21.1:
"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."

Reply via email to