]> git.proxmox.com Git - mirror_qemu.git/commit
qapi: Don't cast Enum* to int*
authorEric Blake <eblake@redhat.com>
Fri, 29 Jan 2016 13:48:52 +0000 (06:48 -0700)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 8 Feb 2016 16:29:55 +0000 (17:29 +0100)
commit395a233f7c089f23e3c0d43ce34c709dc5acd7de
tree698721f9d3101e5294cc10ab12bcbd0f67cdfe84
parent04e070d217b4414f1f91aa8ad25fc0ae7ca0be93
qapi: Don't cast Enum* to int*

C compilers are allowed to represent enums as a smaller type
than int, if all enum values fit in the smaller type.  There
are even compiler flags that force the use of this smaller
representation, although using them changes the ABI of a
binary. Therefore, our generated code for visit_type_ENUM()
(for all qapi enums) was wrong for casting Enum* to int* when
calling visit_type_enum().

It appears that no one has been using compiler ABI switches
for qemu, because if they had, we are potentially dereferencing
beyond bounds or even risking a SIGBUS on platforms where
unaligned pointer dereferencing is fatal.  But it is still
better to avoid the practice entirely, and just use the correct
types.

This matches the fix for alternate qapi types, done earlier in
commit 0426d53 "qapi: Simplify visiting of alternate types",
with generated code changing as:

| void visit_type_QType(Visitor *v, QType *obj, const char *name, Error **errp)
| {
|-    visit_type_enum(v, (int *)obj, QType_lookup, "QType", name, errp);
|+    int value = *obj;
|+    visit_type_enum(v, &value, QType_lookup, "QType", name, errp);
|+    *obj = value;
| }

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-17-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi-visit.py