On 1/22/19 12:18 PM, Peter Maydell wrote:
> Various ipv6 structs in the slirp headers are marked QEMU_PACKED,
> but they are actually naturally aligned and will have no padding
> in them. Instead of marking them with the 'packed' attribute,
> assert at compile time that they are the size we expect. This
> allows us to take the address of fields within the structs
> without risking undefined behaviour, and suppresses clang
> -Waddress-of-packed-member warnings.
> 
> Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
> ---
>  slirp/ip6.h      | 12 ++++++++++--
>  slirp/ip6_icmp.h | 20 +++++++++++++++-----
>  2 files changed, 25 insertions(+), 7 deletions(-)
> 

> +/*
> + * We don't want to mark these ip6 structs as packed as they are naturally
> + * correctly aligned; instead assert that there is no stray padding.
> + * If we marked the struct as packed then we would be unable to take
> + * the address of any of the fields in it.
> + */
> +QEMU_BUILD_BUG_ON(sizeof(struct ip6) != 40);
> +QEMU_BUILD_BUG_ON(sizeof(struct ip6_pseudohdr) != 40);

Nice.  (And IIRC, the IPv6 designers tried to pick natural alignments on
purpose)

Reviewed-by: Eric Blake <ebl...@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to