]> git.proxmox.com Git - mirror_qemu.git/commit - nbd/client.c
nbd: Don't take address of fields in packed structs
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 27 Sep 2018 16:42:00 +0000 (17:42 +0100)
committerEric Blake <eblake@redhat.com>
Wed, 3 Oct 2018 14:58:43 +0000 (09:58 -0500)
commit80c7c2b00d607221bb43815d2c1951d54229b3ee
tree7d9f3932b246f2b17d6ba6d7dbd4f9966c8071b1
parentdafd95053611aa14dda40266857608d12ddce658
nbd: 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.

This patch was produced with the following spatch script:
@@
expression E;
@@
-be16_to_cpus(&E);
+E = be16_to_cpu(E);
@@
expression E;
@@
-be32_to_cpus(&E);
+E = be32_to_cpu(E);
@@
expression E;
@@
-be64_to_cpus(&E);
+E = be64_to_cpu(E);
@@
expression E;
@@
-cpu_to_be16s(&E);
+E = cpu_to_be16(E);
@@
expression E;
@@
-cpu_to_be32s(&E);
+E = cpu_to_be32(E);
@@
expression E;
@@
-cpu_to_be64s(&E);
+E = cpu_to_be64(E);

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20180927164200.15097-1-peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: rebase, and squash in missed changes]
Signed-off-by: Eric Blake <eblake@redhat.com>
nbd/client.c
nbd/server.c