From: Jérémie Galarneau Date: Wed, 4 Sep 2019 16:13:39 +0000 (-0400) Subject: Fix: ctf: assert that name is not NULL in warn_meaningless_field() X-Git-Url: https://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=74ad166b12f92591f5ba5e812227507c6159586d Fix: ctf: assert that name is not NULL in warn_meaningless_field() gcc 9.1 reports that warn_meaningless_field's `name` is sometimes NULL when it is inlined in warn_meaningless_fields(), itself inlined in ctf_trace_class_warn_meaningless_header_fields() at line 131. The the only call site using a `NULL` name will have `fc->type == CTF_FIELD_CLASS_TYPE_STRUCT`. Add a `BT_ASSERT(name)` to warn_meaningless_field() and a comment indicating that `name` is guaranteed to be non-NULL whenever the field class is not a structure. Signed-off-by: Jérémie Galarneau Change-Id: I323b9f390f80dbd898a69664082fd07d5cc2fc86 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2000 Reviewed-by: Simon Marchi Tested-by: jenkins --- diff --git a/src/plugins/ctf/common/metadata/ctf-meta-warn-meaningless-header-fields.c b/src/plugins/ctf/common/metadata/ctf-meta-warn-meaningless-header-fields.c index ebd995f6..9a9d765a 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta-warn-meaningless-header-fields.c +++ b/src/plugins/ctf/common/metadata/ctf-meta-warn-meaningless-header-fields.c @@ -32,6 +32,7 @@ static inline void warn_meaningless_field(const char *name, const char *scope_name, struct meta_log_config *log_cfg) { + BT_ASSERT(name); BT_COMP_LOGW("User field found in %s: ignoring: name=\"%s\"", scope_name, name); } @@ -46,6 +47,11 @@ void warn_meaningless_fields(struct ctf_field_class *fc, const char *name, goto end; } + /* + * 'name' is guaranteed to be non-NULL whenever the field class is not a + * structure. In the case of a structure field class, its members' names + * are used. + */ switch (fc->type) { case CTF_FIELD_CLASS_TYPE_FLOAT: case CTF_FIELD_CLASS_TYPE_STRING: