Skip to contentSkip to conversation

perf-top: Fix uninitialized variable

PATCH In review Akihiro Nagai 1 participant 2 messages Mar 23, 2011 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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
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(-)
tools/perf/builtin-top.c +3 -1
index 70f1075..0e382ff 100644
@@ -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)
#1 lore raw

[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.

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]>

---
 tools/perf/builtin-top.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/builtin-top.c +3 -1
index 70f1075..676b4fb 100644
@@ -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)