This question came up in a code review: are null pointers legal as
arguments to memcpy? That is, is the program at the end of this article
strictly conforming? (Of course, I check the FAQ first and could not
find an answer on point.)
I don't have C89 or C99 handy, so I checked draft N869 from here:
I note the following:
7.21.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.
18.104.22.168 The memcpy function
void *memcpy(void * restrict s1,
const void * restrict s2,
[But see N869 for complete text].
7.1.4 Use of library functions
... unless explicitly stated otherwise in the
detailed descriptions ...
If an argument to a function has an invalid
value (such as ... a null pointer) ... the behavior
So, by my analysis, 7.1.4 says that you must not pass a null pointer to
any library function unless the 7.X documentation allows it. 7.21.1
reenforces 7.1.4, and does not explicity allow a null pointer. 22.214.171.124
also does not explicitly allow a null pointer.
So, memcpy(0,0,0) invokes undefined behavior?