2011-03-23 07:31:31

by Akihiro Nagai

[permalink] [raw]
Subject: [PATCH -tip ] [BUGFIX] perf-top: Fix uninitialized variable

builtin-top.c has an uninitialized valiable.
gcc(version 4.5.1) warns it and results in build failure.

# make
CC builtin-top.o
cc1: warnings being treated as errors
builtin-top.c: In function 'display_thread':
builtin-top.c:518:9: error: 'counter' may be used uninitialized in this function
builtin-top.c:518:9: note: 'counter' was declared here
make: *** [builtin-top.o] Error 1

Signed-off-by: Akihiro Nagai <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
---

tools/perf/builtin-top.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 70f1075..0e382ff 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -515,7 +515,9 @@ static void handle_keypress(struct perf_session *session, int c)
break;
case 'E':
if (top.evlist->nr_entries > 1) {
- int counter;
+ /* Select 0 as default event */
+ int counter = 0;
+
fprintf(stderr, "\nAvailable events:");

list_for_each_entry(top.sym_evsel, &top.evlist->entries, node)


2011-03-23 09:43:38

by Akihiro Nagai

[permalink] [raw]
Subject: [tip:perf/urgent] perf top: Fix uninitialized 'counter' variable

Commit-ID: ce2d17ca7f85dcade62cd608601a0d52ccdaf0e6
Gitweb: http://git.kernel.org/tip/ce2d17ca7f85dcade62cd608601a0d52ccdaf0e6
Author: Akihiro Nagai <[email protected]>
AuthorDate: Wed, 23 Mar 2011 16:29:39 +0900
Committer: Ingo Molnar <[email protected]>
CommitDate: Wed, 23 Mar 2011 10:38:32 +0100

perf top: Fix uninitialized 'counter' variable

builtin-top.c has an uninitialized variable.
gcc(version 4.5.1) warns about it and it results in build failure:

builtin-top.c: In function 'display_thread':
builtin-top.c:518:9: error: 'counter' may be used uninitialized

This situation can indeed trigger, if the getline() call in
prompt_integer() fails.

Signed-off-by: Akihiro Nagai <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
tools/perf/builtin-top.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 70f1075..676b4fb 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -515,7 +515,9 @@ static void handle_keypress(struct perf_session *session, int c)
break;
case 'E':
if (top.evlist->nr_entries > 1) {
- int counter;
+ /* Select 0 as the default event: */
+ int counter = 0;
+
fprintf(stderr, "\nAvailable events:");

list_for_each_entry(top.sym_evsel, &top.evlist->entries, node)