From 7ba27414a45c718b9d90567e0944f5ff149ad455 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 20 Mar 2016 21:09:02 +0000 Subject: [PATCH] tools lib traceevent: Fix use of uninitialized variables Fix a number of correct warnings from gcc: > plugin_function.c:133:6: warning: 'index' may be used uninitialized in this function [-Wmaybe-uninitialized] > int index; > ^ 'index' is initialized only if indentation is wanted. Move the printing of indentation using 'index' into the same if-statement. > kbuffer-parse.c:339:27: warning: 'length' may be used uninitialized in this function [-Wmaybe-uninitialized] > kbuf->next = kbuf->index + length; > ^ > kbuffer-parse.c:297:15: note: 'length' was declared here > unsigned int length; > ^ 'length' is not initialized when handling an OLD_RINGBUF_TYPE_TIME_EXTEND record. Based on what trace-cmd does, set length = 0 in this case. > kbuffer-parse.c: In function 'kbuffer_read_at_offset': > kbuffer-parse.c:632:9: warning: 'data' may be used uninitialized in this function [-Wmaybe-uninitialized] > return data; > ^ 'data' is not initialized if the offset is too small. Initialize it to NULL so that the behaviour is the same as when the offset is too large. Signed-off-by: Ben Hutchings Gbp-Pq: Topic bugfix/all Gbp-Pq: Name tools-lib-traceevent-fix-use-of-uninitialized-variables.patch --- tools/lib/traceevent/kbuffer-parse.c | 3 ++- tools/lib/traceevent/plugin_function.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lib/traceevent/kbuffer-parse.c b/tools/lib/traceevent/kbuffer-parse.c index 65984f1c2974..56db64838c8e 100644 --- a/tools/lib/traceevent/kbuffer-parse.c +++ b/tools/lib/traceevent/kbuffer-parse.c @@ -314,6 +314,7 @@ static unsigned int old_update_pointers(struct kbuffer *kbuf) extend <<= TS_SHIFT; extend += delta; delta = extend; + length = 0; ptr += 4; break; @@ -613,7 +614,7 @@ unsigned long long kbuffer_timestamp(struct kbuffer *kbuf) void *kbuffer_read_at_offset(struct kbuffer *kbuf, int offset, unsigned long long *ts) { - void *data; + void *data = NULL; if (offset < kbuf->start) offset = 0; diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c index a00ec190821a..cb6b25c81aaf 100644 --- a/tools/lib/traceevent/plugin_function.c +++ b/tools/lib/traceevent/plugin_function.c @@ -142,10 +142,10 @@ static int function_handler(struct trace_seq *s, struct pevent_record *record, parent = pevent_find_function(pevent, pfunction); - if (parent && ftrace_indent->set) + if (parent && ftrace_indent->set) { index = add_and_get_index(parent, func, record->cpu); - - trace_seq_printf(s, "%*s", index*3, ""); + trace_seq_printf(s, "%*s", index*3, ""); + } if (func) trace_seq_printf(s, "%s", func); -- 2.30.2