Re: [PATCH] building libtraceevent with clang
From: Steven Rostedt
Date: Mon Feb 13 2017 - 12:47:19 EST
On Mon, 13 Feb 2017 14:20:20 -0300
Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
> Sure, now take a look at this another one:
>
> commit 6401e4361df183bd9953dce56f7c51d8ef28b11e
> Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Date: Mon Feb 13 13:33:57 2017 -0300
>
> tools lib traceevent plugin function: Initialize 'index' variable
>
> Detected with clang:
>
> CC /tmp/build/perf/plugin_function.o
> plugin_function.c:145:6: warning: variable 'index' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> if (parent && ftrace_indent->set)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> plugin_function.c:148:29: note: uninitialized use occurs here
> trace_seq_printf(s, "%*s", index*3, "");
> ^~~~~
> plugin_function.c:145:2: note: remove the 'if' if its condition is always true
> if (parent && ftrace_indent->set)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> plugin_function.c:145:6: warning: variable 'index' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
> if (parent && ftrace_indent->set)
> ^~~~~~
> plugin_function.c:148:29: note: uninitialized use occurs here
> trace_seq_printf(s, "%*s", index*3, "");
> ^~~~~
> plugin_function.c:145:6: note: remove the '&&' if its condition is always true
> if (parent && ftrace_indent->set)
> ^~~~~~~~~
> plugin_function.c:133:11: note: initialize the variable 'index' to silence this warning
> int index;
> ^
> = 0
> 2 warnings generated.
I wonder why gcc isn't catching these. These look pretty obvious to me.
>
> Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> Cc: David Ahern <dsahern@xxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Wang Nan <wangnan0@xxxxxxxxxx>
> Link: http://lkml.kernel.org/n/tip-b5wyjocel55gorl2jq2cbxrr@xxxxxxxxxxxxxx
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>
> diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c
> index a00ec190821a..42dbf73758f3 100644
> --- a/tools/lib/traceevent/plugin_function.c
> +++ b/tools/lib/traceevent/plugin_function.c
> @@ -130,7 +130,7 @@ static int function_handler(struct trace_seq *s, struct pevent_record *record,
> unsigned long long pfunction;
> const char *func;
> const char *parent;
> - int index;
> + int index = 0;
>
> if (pevent_get_field_val(s, event, "ip", record, &function, 1))
> return trace_seq_putc(s, '!');
>
Reviewed-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
-- Steve