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

Eric Blake eblake at redhat.com
Fri Apr 5 20:26:29 UTC 2013


On 04/03/2013 09:06 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at 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.

ACK.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130405/9ecefa08/attachment-0001.sig>


More information about the libvir-list mailing list