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

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

 



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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]