svn commit: r253636 - head/sys/vm

mdf at mdf at
Thu Jul 25 15:10:45 UTC 2013

On Thu, Jul 25, 2013 at 4:43 AM, David Chisnall <theraven at>wrote:

> However(), memset is to be preferred in this idiom because the compiler
> provides better diagnostics in the case of error:
> bzero.c:9:22: warning: 'memset' call operates on objects of type 'struct
> foo'
>       while the size is based on a different type 'struct foo *'
>       [-Wsizeof-pointer-memaccess]
>         memset(f, 0, sizeof(f));
>                ~            ^
> bzero.c:9:22: note: did you mean to dereference the argument to 'sizeof'
> (and
>       multiply it by the number of elements)?
>         memset(f, 0, sizeof(f));
>                             ^
> The same line with bzero(f, sizeof(f)) generates no error.

Isn't that a compiler bug?  memset(p, 0, n) is the same as bzero(p, n).
 Why would the compiler warn on one and not the other?

Does clang have a similar bias for memcpy versus bcopy?


More information about the svn-src-head mailing list