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

Nico Weber thakis at chromium.org
Mon Jun 13 08:14:19 PDT 2011

On Mon, Jun 13, 2011 at 12:49 AM, Hans Wennborg <hans at chromium.org> wrote:
> 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?

I decided against a fixit because it is not always correct. In fact,
in chrome 2 of 3 instances of this warning were about pointers to
arrays and the fix was different from just inserting a *. Maybe even
the diagnostic wording is a bit strong, but I couldn't think of
anything better.


More information about the cfe-commits mailing list