On Tue, Apr 15, 2014 at 08:06:57AM +0200, Alan Barrett wrote: > 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 > 7.1.4. > > 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 7.21.2.1 "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.
I remember a discussion about this topic from the LLVM lists and the reasons for the standard language on this are extremely weak. IIRC the *only* justification was for some platforms with broken (trapping) prefetch instructions. Joerg