From a0c7b99bf75d85b616fa219a7d866fc72970f327 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 16 Jun 2021 09:21:21 +0200 Subject: qapi: Fix crash on missing enum member name New test case enum-dict-no-name.json crashes: $ python3 scripts/qapi-gen.py tests/qapi-schema/enum-dict-no-name.json Traceback (most recent call last): [...] File "/work/armbru/qemu/scripts/qapi/expr.py", line 458, in check_enum member_name = member['name'] KeyError: 'name' Root cause: we try to retrieve member 'name' before we check for missing members. With that fixed, we get the expected error "'data' member misses key 'name'". Fixes: 0825f62c842f2c07c5471391c6d7fd3f4fe83732 Signed-off-by: Markus Armbruster Message-Id: <20210616072121.626431-1-armbru@redhat.com> Reviewed-by: Eric Blake Reviewed-by: John Snow --- tests/qapi-schema/enum-dict-no-name.err | 2 ++ tests/qapi-schema/enum-dict-no-name.json | 2 ++ tests/qapi-schema/enum-dict-no-name.out | 0 3 files changed, 4 insertions(+) create mode 100644 tests/qapi-schema/enum-dict-no-name.err create mode 100644 tests/qapi-schema/enum-dict-no-name.json create mode 100644 tests/qapi-schema/enum-dict-no-name.out (limited to 'tests') diff --git a/tests/qapi-schema/enum-dict-no-name.err b/tests/qapi-schema/enum-dict-no-name.err new file mode 100644 index 0000000..3ce0c16 --- /dev/null +++ b/tests/qapi-schema/enum-dict-no-name.err @@ -0,0 +1,2 @@ +enum-dict-no-name.json: In enum 'Enum': +enum-dict-no-name.json:2: 'data' member misses key 'name' diff --git a/tests/qapi-schema/enum-dict-no-name.json b/tests/qapi-schema/enum-dict-no-name.json new file mode 100644 index 0000000..5952a86 --- /dev/null +++ b/tests/qapi-schema/enum-dict-no-name.json @@ -0,0 +1,2 @@ +# enum member lacking a name +{ 'enum': 'Enum', 'data': [ {} ] } diff --git a/tests/qapi-schema/enum-dict-no-name.out b/tests/qapi-schema/enum-dict-no-name.out new file mode 100644 index 0000000..e69de29 -- cgit v1.1