From 261e7f1360fffe91b0b690c8a0715f4f6d2c4a7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 18 Oct 2021 14:43:18 -0400 Subject: [PATCH] Fix: lttng: add-context: silence coverity warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Coverity reports that: 1464653 Uninitialized scalar field The field will contain an arbitrary value left over from earlier computations. In ctx_opts::​ctx_opts(): A scalar field is not initialized by the constructor. uninit_member: Non-static class member hide_help is not initialized in this constructor nor in any functions that it calls. In our case it doesn't matter since a nullptr symbol indicates the end the ctx_opts array. An "unknown" value is added to the context array and used to initialize the end-of-list item to an invalid value. Calling the ctx_opts(const char *symbol_, context_type ctx_type_, bool hide_help_ = false) constructor causes `hide_help` to be initialized. Signed-off-by: Jérémie Galarneau Change-Id: Ie685fef5712705a1938d9e6b8a63d23ab5bc6b39 --- src/bin/lttng/commands/add_context.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng/commands/add_context.cpp b/src/bin/lttng/commands/add_context.cpp index d078471d3..076fa83a4 100644 --- a/src/bin/lttng/commands/add_context.cpp +++ b/src/bin/lttng/commands/add_context.cpp @@ -51,9 +51,10 @@ static struct lttng_handle *handle; static struct mi_writer *writer; /* - * Taken from the LTTng ABI + * Taken from the LTTng ABI except for "UNKNOWN". */ enum context_type { + CONTEXT_UNKNOWN = -1, CONTEXT_PID = 0, CONTEXT_PERF_COUNTER = 1, /* Backward compat. */ CONTEXT_PROCNAME = 2, @@ -220,7 +221,7 @@ static const struct ctx_opts { /* Needed for end-of-list item. */ ctx_opts() - : symbol(nullptr) + : ctx_opts(nullptr, CONTEXT_UNKNOWN) {} ctx_opts(const char *symbol_, context_type ctx_type_, bool hide_help_ = false) -- 2.34.1