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

Jordy Rose jediknil at belkadan.com
Mon Jun 13 12:18:09 PDT 2011


On Jun 13, 2011, at 8:32, Nico Weber wrote:

> On Mon, Jun 13, 2011 at 8:15 AM, Anders Carlsson <andersca at mac.com> wrote:
>> 
>> On Jun 12, 2011, at 10:23 PM, Nico Weber 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.
>> 
>> This diagnostic doesn't sound quite right. It's not the sizeof expression that has type 'S *' (the sizeof expression always has type size_t).
> 
> Yes, I'm not too happy with the diag wording. I had "The sizeof
> argument in…" first, but that made  "…that the first argument has"
> ambiguous. Maybe just "Using sizeof pointer type ('S *') instead of
> expected type 'S'."? Phrasing suggestions welcome :-)

How about "The argument to sizeof is pointer type 'S *', expected 'S'", with a note "attempting to match this expression" or something (which points to the first argument to memset).



More information about the cfe-commits mailing list