From 6672c9efe1e1ab04f22a8abbd77f8adb5bcefb0a Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Tue, 18 Dec 2018 15:47:20 -0500 Subject: [PATCH] Fix: may be used uninitialized trace_name variable This fixes the following Clang warning: dmesg.c:263:7: error: variable 'trace_name' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dmesg.c:269:6: note: uninitialized use occurs here if (trace_name) { ^~~~~~~~~~ dmesg.c:263:3: note: remove the 'if' if its condition is always true if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dmesg.c:263:7: error: variable 'trace_name' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized] if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dmesg.c:269:6: note: uninitialized use occurs here if (trace_name) { ^~~~~~~~~~ dmesg.c:263:7: note: remove the '&&' if its condition is always true if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dmesg.c:248:24: note: initialize the variable 'trace_name' to silence this warning const char *trace_name; Signed-off-by: Francis Deslauriers --- plugins/text/dmesg/dmesg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 1ec86744b..c70fd1eb6 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -245,7 +245,7 @@ static int create_packet_and_stream_and_trace(struct dmesg_component *dmesg_comp) { int ret = 0; - const char *trace_name; + const char *trace_name = NULL; gchar *basename = NULL; dmesg_comp->trace = bt_trace_create(dmesg_comp->trace_class); -- 2.34.1