This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [wwwdocs] gcc-4.8/porting_to.html


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.


Alexander


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]