Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/common/lib/libc/string

On Mon, 14 Apr 2014, Joerg Sonnenberger wrote:
Modified Files:
        src/common/lib/libc/string: bcopy.c

Log Message:
Using bcopy/memcpy with NULL arguments is valid as long as the size is
also 0.

No, it's undefined behaviour.  C99 section 7.21.1:

   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

and 7.1.4 says:

   If an argument to a function has an invalid value (such as ...
   a null pointer ...) ..., the behavior is undefined.

and "The memcpy function" does not give any explicit permission for use of null pointers.

I don't object if the implementation wants to allow null pointers with zero size as an extension, but it should be clear that this is non-standard.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index