From bc85036fc10e20cee79e2b43d9bbde8e4d1ca04a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 8 Nov 2017 10:55:16 -0500 Subject: [PATCH] Fix: uninitialized variable may be used warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc 7.2 warns of potentially uninitialized variables being used as the callers rely on output parameters being initialized by the callees on error. This behaviour is not specified as part of the API so relying on this is iffy. Signed-off-by: Jérémie Galarneau --- lib/ctf-ir/field-types.c | 2 +- plugins/ctf/common/metadata/visitor-generate-ir.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index a6ebdb39..c2a5383c 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -2977,7 +2977,7 @@ int bt_field_type_get_alignment(struct bt_field_type *type) assert(element_count >= 0); for (i = 0; i < element_count; i++) { - struct bt_field_type *field; + struct bt_field_type *field = NULL; int field_alignment; ret = bt_field_type_structure_get_field_by_index( diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index aae7322b..734ed996 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -3258,7 +3258,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, _SET(set, _EVENT_NAME_SET); } else if (!strcmp(left, "id")) { - int64_t id; + int64_t id = -1; if (_IS_SET(set, _EVENT_ID_SET)) { _BT_LOGE_DUP_ATTR(node, "id", @@ -4873,7 +4873,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, g_free(right); _SET(set, _CLOCK_DESCRIPTION_SET); } else if (!strcmp(left, "freq")) { - uint64_t freq; + uint64_t freq = -1ULL; if (_IS_SET(set, _CLOCK_FREQ_SET)) { _BT_LOGE_DUP_ATTR(entry_node, "freq", "clock class"); -- 2.34.1