From c5fe2e6f59c1d901921b36d30332404dd8394dae Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Tue, 30 Apr 2019 11:28:48 -0400 Subject: [PATCH] Fix: maybe-uninitialized warnings in translate-trace-ir-to-ctf-ir.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit GCC warning example: translate-trace-ir-to-ctf-ir.c:929:14: error: ‘struct_fc’ may be used uninitialized in this function [-Werror=maybe-uninitialized] named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_index( ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct_fc, i); ~~~~~~~~~~~~~ Signed-off-by: Francis Deslauriers Change-Id: I24ba8095f26cec640e0a24473b4fee05d1c404af Reviewed-on: https://review.lttng.org/c/babeltrace/+/1032 Reviewed-by: Philippe Proulx --- .../ctf/fs-sink/translate-trace-ir-to-ctf-ir.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c b/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c index fe3725f8..72f5e4a8 100644 --- a/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c +++ b/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c @@ -172,6 +172,7 @@ int create_relative_field_ref(struct ctx *ctx, { int ret = 0; struct fs_sink_ctf_field_class *tgt_fc = NULL; + enum fs_sink_ctf_field_class_type tgt_fc_type; uint64_t i; int64_t si; const char *tgt_fc_name = NULL; @@ -200,6 +201,7 @@ int create_relative_field_ref(struct ctx *ctx, } i = 0; + tgt_fc_type = tgt_fc->type; while (i < bt_field_path_get_item_count(tgt_ir_field_path)) { const bt_field_path_item *fp_item = @@ -210,7 +212,7 @@ int create_relative_field_ref(struct ctx *ctx, BT_ASSERT(tgt_fc); BT_ASSERT(fp_item); - switch (tgt_fc->type) { + switch (tgt_fc_type) { case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT: BT_ASSERT(bt_field_path_item_get_type(fp_item) == BT_FIELD_PATH_ITEM_TYPE_INDEX); @@ -248,7 +250,7 @@ int create_relative_field_ref(struct ctx *ctx, } BT_ASSERT(tgt_fc); - BT_ASSERT(tgt_fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT); + BT_ASSERT(tgt_fc_type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT); BT_ASSERT(tgt_fc_name); /* Find target field class having this name in current context */ @@ -900,9 +902,12 @@ int set_field_refs(struct fs_sink_ctf_field_class *fc, const char *fc_name, struct fs_sink_ctf_field_class *parent_fc) { int ret = 0; + enum fs_sink_ctf_field_class_type fc_type; BT_ASSERT(fc); - switch (fc->type) { + fc_type = fc->type; + + switch (fc_type) { case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT: case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT: { @@ -912,7 +917,7 @@ int set_field_refs(struct fs_sink_ctf_field_class *fc, const char *fc_name, struct fs_sink_ctf_field_class_variant *var_fc; struct fs_sink_ctf_named_field_class *named_fc; - if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) { + if (fc_type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) { struct_fc = (void *) fc; len = struct_fc->members->len; } else { @@ -925,7 +930,7 @@ int set_field_refs(struct fs_sink_ctf_field_class *fc, const char *fc_name, } for (i = 0; i < len; i++) { - if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) { + if (fc_type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) { named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_index( struct_fc, i); } else { @@ -948,7 +953,7 @@ int set_field_refs(struct fs_sink_ctf_field_class *fc, const char *fc_name, struct fs_sink_ctf_field_class_array_base *array_base_fc = (void *) fc; - if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE) { + if (fc_type == FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE) { ret = set_field_ref(fc, fc_name, parent_fc); if (ret) { goto end; -- 2.34.1