[cfe-commits] r133136 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/warn-memset-bad-sizeof.cpp
Chandler Carruth
chandlerc at gmail.com
Wed Jun 15 21:21:55 PDT 2011
On Wed, Jun 15, 2011 at 8:15 PM, Nico Weber <thakis at chromium.org> wrote:
> You added
>
> char c = 42;
> char* parr[5];
> memcpy(&parr[3], &c, sizeof(&c));
>
> Doesn't this copy the (typically) 4-byte pointer parr[3] into the
> 1-byte memory occupied by c? Shouldn't this be
>
> char* c;
> char* parr[5];
> memcpy(&parr[3], &c, sizeof(c));
>
> (In which case the old version wouldn't warn either.)
>
> /me feels blind
>
Yea.... this test case didn't end up being what I wanted. Sorry. I think I
was editting it too quickly. I've provided a better test case in r133143.
I'm still not sure what the right policy is, I'm looking at how hard it
would be to warn on 'memset(x, 0, sizeof(x))' where 'x' is an identical
expression with pointer type as that seems much more reasonable to do even
if the type is 'char*'.
For any purely type-based warning, I feel like in principle we shouldn't
warn on essentially any uses of 'char*' or 'void*' because those types have
special meaning and uses in conjunction w/ memcpy etc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110615/337b7eb0/attachment.html>
More information about the cfe-commits
mailing list