+Richard C99 (and C11) standards suggests passing NULL to memcpy is an undefined behavior:
7.21.1.2 (String function conventions): 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. 7.1.4.1 If an argument to a function has an invalid value (such as a <...> null pointer <...>) <...> the behavior is undefined. I'm not sure if it's overriden by POSIX/Linux, though, and if GCC has full right to optimize on this. On Mon, May 11, 2015 at 2:40 PM, Nuno Lopes <[email protected]> wrote: > On Mon, May 11, 2015 at 07:00:53PM +0000, Nuno Lopes wrote: >> >>> gcc 4.9 just got more aggressive and is now exploiting the fact that >>> input pointers to memcpy/memmove cannot be null (even if the size is 0). >>> >> >> Are you sure that this is GCC and not glibc? Can someone *please* raise >> a defect report against the C standard? This is ridiculous... >> > > I had to debug a big project over this weekend because it was being > miscompiled with gcc 4.9. > Apparently the porting guide (https://gcc.gnu.org/gcc-4.9/porting_to.html) > states that gcc is now more aggressive in optimizing away null pointer > checks. > > Nuno > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > -- Alexey Samsonov [email protected]
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
