[cfe-commits] [patch] Warn on memset(p, 0, sizeof(p))

Hans Wennborg hans at chromium.org
Mon Jun 13 00:49:44 PDT 2011

Hi Nico,

On Mon, Jun 13, 2011 at 6:23 AM, Nico Weber <thakis at chromium.org> wrote:
> Hi,
> the attached patch produces this diagnostic
>  test.cpp:16:17: warning: The sizeof expression in 'memset' has type
> 'S *', the same type that the first argument has. The sizeof
> expression should probably have type 'S' instead.

Would it be possible to issue a fixit to insert a '*' in the right
place? I suppose it might not work very well with arrays though?

The code itself looks fine as far as I can tell.

> for this code:
>  struct S {};
>  S* ps;
>  memset(ps, 0, sizeof(ps));  // Should be sizeof(*ps)
> This is PR9977.
> Ok?
> I've built llvm, clang, and parts of chrome with this patch.
> llvm/clang build fine; in chrome I found at least one error with this
> already. (chrome doesn't build cleanly with ToT clang at the moment
> for other reasons, so I can't do a full evaluation at the moment.)
> Nico
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

More information about the cfe-commits mailing list