<div style="font-family: arial, helvetica, sans-serif"><font size="2"><div class="gmail_quote">On Wed, Jun 13, 2012 at 10:21 AM, Chris Pickel <span dir="ltr"><<a href="mailto:sfiera@sfzmail.com" target="_blank">sfiera@sfzmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, cfe-commits,<br>
<br>
After spending far too long tracking down a bug which was ultimately<br>
caused by the line:<br>
<br>
memset(&x, sizeof(x), 0); // Should be memset(&x, 0, sizeof(x))<br></blockquote><div><br></div><div>FWIW, I think this makes more sense w/ memset than any others -- 0 isn't valid for either the source or destination of memcpy / memcmp / memmove.</div>
<div><br></div><div>Also, I would want to make sure that the '0' is not actually computed from a macro or template parameter.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I wrote a clang patch which adds a diagnostic for this situation. It<br>
warns on any call to a memaccess function (memset, memcpy, memcmp,<br>
&c.) in which a literal "0" is passed as the size. Like other<br>
memaccess diagnostics, it can be suppressed by casting &x to void*.<br>
<br>
The git-formatted patch is attached, but it fails a few tests, and I'm<br>
not sure what the correct fix is. The test log is attached too; a<br>
summary is:<br>
<br>
Analysis/bstring.c:<br>
"TRUE" warnings expected in addition to zero-length memaccess warnings<br>
<br>
Analysis/string.c<br>
Warns on __builtin_strncpy instead of strcpy<br>
But if I change the expectation, then it warns on strcpy instead<br>
<br>
SemaCXX/warn-zero-length-memaccess:<br>
SemaCXX/zero-length-arrays:<br>
Implicit copy-constructors appear to generate calls to<br>
__builtin_memcpy(…, 0)<br>
This warning shouldn't really be checking __builtin_memcpy()<br>
On the other hand, should __builtin_memcpy(…, 0) be generated to begin with?<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">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>
<br></blockquote></div><br></font></div>