This is explicitly required in 7.1.4 of C99:

      7.1.4 Use of library functions

  -1- Each of the following statements applies unless explicitly stated
      otherwise in the detailed descriptions that follow: If an argument
      to a function has an invalid value (such as a value outside the
      domain of the function, or a pointer outside the address space
      of the program, or a null pointer, or a pointer to non-modifiable
      storage when the corresponding parameter is not const-qualified)
      or a type (after promotion) not expected by a function with
      variable number of arguments, the behavior is undefined. ...

Here's an answer to the same question on comp.lang.c.moderated:
  http://tinyurl.com/6eqo3n

Martin Sebor wrote:
Eric Lemings wrote:
Is it safe to pass a null pointer as the 2nd argument to memcpy()? Or
undefined?

Assuming the third argument is 0. Strictly speaking I believe it's
undefined because memcpy(s1, s2, n) is specified to "copy n bytes
from the object pointed to by s2 into the object pointed to by s1"
and a null pointer doesn't point to an object. An object is defined
as "a region of storage in the execution environment, the contents
of which can represent values."

AFAIK, most implementations allow null pointers for no-op calls to
memcpy() but gcc issues a warning when it detects at compile time
that a null pointer is passed as the first or second argument to
memcpy().

Martin


Reply via email to