From: Jérémie Galarneau Date: Wed, 13 May 2015 18:07:37 +0000 (-0400) Subject: ir: support optional parameters in bt_ctf_field_type_variant_get_field X-Git-Tag: v2.0.0-pre1~1233 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=647f3b934f62d237443c339cc8bff87b1b213794 ir: support optional parameters in bt_ctf_field_type_variant_get_field Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index c03f0b77..fabaea51 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -1487,8 +1487,7 @@ int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *type, struct structure_field *field; int ret = 0; - if (!type || index < 0 || !field_name || !field_type || - (type->declaration->id != CTF_TYPE_VARIANT)) { + if (!type || index < 0 || (type->declaration->id != CTF_TYPE_VARIANT)) { ret = -1; goto end; } @@ -1501,9 +1500,13 @@ int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *type, } field = g_ptr_array_index(variant->fields, index); - *field_type = field->type; - bt_ctf_field_type_get(field->type); - *field_name = g_quark_to_string(field->name); + if (field_type) { + *field_type = field->type; + bt_ctf_field_type_get(field->type); + } + if (field_name) { + *field_name = g_quark_to_string(field->name); + } end: return ret; } diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 47096354..368c1e9f 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -883,9 +883,10 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_field_type_variant_get_field(NULL, &ret_string, &ret_field_type, 0) < 0, "bt_ctf_field_type_variant_get_field handles a NULL type correctly"); - ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) < 0, + ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) == 0, "bt_ctf_field_type_variant_get_field handles a NULL field name correctly"); - ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) < 0, + bt_ctf_field_type_put(ret_field_type); + ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) == 0, "bt_ctf_field_type_variant_get_field handles a NULL field type correctly"); ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0, "bt_ctf_field_type_variant_get_field handles an invalid index correctly");