<div dir="ltr"><div>+Richard</div><div><br></div>C99 (and C11) standards suggests passing NULL to memcpy is an undefined behavior:<div><br></div><div><div>7.21.1.2 (String function conventions): Unless explicitly stated otherwise in the description of a particular function</div><div>in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. </div><div><br></div><div><div>7.1.4.1 If an argument to a function has an invalid value (such as a <...></div><div>null pointer <...>) <...> the behavior is undefined.</div></div><div><br></div><div>I'm not sure if it's overriden by POSIX/Linux, though, and if GCC has full right to optimize on this.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 11, 2015 at 2:40 PM, Nuno Lopes <span dir="ltr"><<a href="mailto:nunoplopes@sapo.pt" target="_blank">nunoplopes@sapo.pt</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On Mon, May 11, 2015 at 07:00:53PM +0000, Nuno Lopes wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
gcc 4.9 just got more aggressive and is now exploiting the fact that<br>
input pointers to memcpy/memmove cannot be null (even if the size is 0).<br>
</blockquote>
<br>
Are you sure that this is GCC and not glibc? Can someone *please* raise<br>
a defect report against the C standard? This is ridiculous...<br>
</blockquote>
<br></span>
I had to debug a big project over this weekend because it was being miscompiled with gcc 4.9.<br>
Apparently the porting guide (<a href="https://gcc.gnu.org/gcc-4.9/porting_to.html" target="_blank">https://gcc.gnu.org/gcc-4.9/porting_to.html</a>) states that gcc is now more aggressive in optimizing away null pointer checks.<span class=""><font color="#888888"><br>
<br>
Nuno <br></font></span><div class=""><div class="h5">
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div></div></div>