On Thu, Mar 14, 2013 at 03:07:36PM +0400, Alexander Monakov wrote:
> 
> It still references memcpy in -Wsizeof-pointer-memaccess section.  Let me
> suggest instead:
> 
>     To fix, properly pass the size of cleared memory as the last argument:
>     either dereference the pointer argument to sizeof when clearing *one
>     pointed-to element*, or in addition to that multiply sizeof(*p) by the
>     number of elements to clear in the pointed-to array (which may not be
>     known at the point of memset call without additional code changes).
> 
> 
> 
> I suppose a good chunk of problematic code hitting this warning would be doing
> something like:
> 
>     void foo(int a[])
>     {
>       memset(a, 0, sizeof(a));
>     }
> 
> ... in which case dereferencing a in sizeof is probably the wrong thing to do.

The has different wording for the different cases, can suggest you to
1) remove addressof
2) provide an explicit length
3) dereference it

E.g. 1) is for cases like memset (&a, 0, sizeof (&a)); where removing the &
is usually the right thing to do.

        Jakub

Reply via email to