block/vdi: Don't take address of fields in packed structs
commit091901841af285f963ea80cd18d616fd0350ddbc
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 16 Oct 2018 17:25:03 +0000 (16 18:25 +0100)
committerKevin Wolf <kwolf@redhat.com>
Mon, 5 Nov 2018 14:09:54 +0000 (5 15:09 +0100)
treef7538c1d3ed125ca8b98babf88b7986e45607b11
parent1229e46d3cfe61ee0b11f08fbbc7530af1578637
block/vdi: Don't take address of fields in packed structs

Taking the address of a field in a packed struct is a bad idea, because
it might not be actually aligned enough for that pointer type (and
thus cause a crash on dereference on some host architectures). Newer
versions of clang warn about this. Avoid the bug by not using the
"modify in place" byte swapping functions.

There are a few places where the in-place swap function is
used on something other than a packed struct field; we convert
those anyway, for consistency.

Patch produced with scripts/coccinelle/inplace-byteswaps.cocci.

There are other places where we take the address of a packed member
in this file for other purposes than passing it to a byteswap
function (all the calls to qemu_uuid_*()); we leave those for now.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/vdi.c