[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 2/7] Avoid casts between unsigned char * and struct nlmsghdr

On 04/03/2013 09:06 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange redhat com>
> The virNetlinkCommand() method takes an 'unsigned char **'
> parameter to be filled with the received netlink message.
> The callers then immediately cast this to 'struct nlmsghdr',
> triggering (bogus) warnings about increasing alignment
> requirements

Not bogus warnings unless all callers were really passing in something
that was already aligned to struct nlmsghdr requirements.  But your
analysis was right - the pointer was properly aligned.

> util/virnetdev.c: In function 'virNetDevLinkDump':
> util/virnetdev.c:1300:12: warning: cast increases required alignment of target type [-Wcast-align]
>      resp = (struct nlmsghdr *)*recvbuf;
>             ^

> Since all callers cast to 'struct nlmsghdr' we can avoid
> the warning problem entirely by simply changing the
> signature of virNetlinkCommand to return a 'struct nlmsghdr **'
> instead of 'unsigned char **'. The way we do the cast inside
> virNetlinkCommand does not have any alignment issues.

Yeah, telling the compiler the correct type to begin with is better anyways.


Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]