From e9eb537e05548ea948c80bad88789303e0c14b75 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 2 May 2017 17:19:53 -0400 Subject: [PATCH] Fix: ir: bt_ctf_field_type_variant_validate(): do not compare to tag length MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Because the same label can map to multiple values in an enumeration FT, the number of fields in a variant FT does not need to be the same as the number of mappings in its tag FT for the variant FT to be considered valid. Relax this by only making sure that each tag FT mapping has an entry in the variant FT which shares the same name. Unused variant FT fields/choices are not a problem per se, just a waste of space. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- lib/ctf-ir/field-types.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index 2c334183..3ce3758b 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -683,11 +683,14 @@ int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type) bt_ctf_field_type_enumeration_get_mapping_count( (struct bt_ctf_field_type *) variant->tag); - if (tag_mappings_count != variant->fields->len) { - ret = -1; - goto end; - } - + /* + * Validate that each mapping found in the tag has a name which + * is also the name of a field in this variant field type. + * + * The opposite is accepted: variant FT fields which cannot be + * selected because the variant FT tag has no mapping named as + * such. This scenario, while not ideal, cannot cause any error. + */ for (i = 0; i < tag_mappings_count; ++i) { const char *label; struct bt_ctf_field_type *ft; -- 2.34.1