From: Philippe Proulx Date: Tue, 2 May 2017 21:19:53 +0000 (-0400) Subject: Fix: ir: bt_ctf_field_type_variant_validate(): do not compare to tag length X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=e9eb537e05548ea948c80bad88789303e0c14b75;p=deliverable%2Fbabeltrace.git Fix: ir: bt_ctf_field_type_variant_validate(): do not compare to tag length 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 --- diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index 2c334183e..3ce3758b8 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;