Skip to contentSkip to conversation

libperf tests: Avoid uninitialized variable warning.

PATCH Applied Ian Rogers 4 participants 4 messages Jan 14, 2021 – Jan 15, 2021 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 libperf tests: Avoid uninitialized variable warning.

The variable bf is read (for a write call) without being initialized triggering a memory sanitizer warning. Use bf in the read and switch the write to reading from a string.

---
 tools/lib/perf/tests/test-evlist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/perf/tests/test-evlist.c +2 -2
index 6d8ebe0c2504..1b225fe34a72 100644
@@ -208,7 +208,6 @@ static int test_mmap_thread(void)
 	char path[PATH_MAX];
 	int id, err, pid, go_pipe[2];
 	union perf_event *event;
-	char bf;
 	int count = 0;
 
 	snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
@@ -229,6 +228,7 @@ static int test_mmap_thread(void)
 	pid = fork();
 	if (!pid) {
 		int i;
+		char bf;
 
 		read(go_pipe[0], &bf, 1);
 
@@ -266,7 +266,7 @@ static int test_mmap_thread(void)
 	perf_evlist__enable(evlist);
 
 	/* kick the child and wait for it to finish */
-	write(go_pipe[1], &bf, 1);
+	write(go_pipe[1], "A", 1);
 	waitpid(pid, NULL, 0);
 
 	/*
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Ian,

Quoted 6 lines · Ian Rogers

The variable bf is read (for a write call) without being initialized triggering a memory sanitizer warning. Use bf in the read and switch the write to reading from a string.

Thanks,
Namhyung

Quoted 36 lines
---
 tools/lib/perf/tests/test-evlist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/perf/tests/test-evlist.c +2 -3
index 6d8ebe0c2504..1b225fe34a72 100644
@@ -208,7 +208,6 @@ static int test_mmap_thread(void)
        char path[PATH_MAX];
        int id, err, pid, go_pipe[2];
        union perf_event *event;
-       char bf;
        int count = 0;
 
        snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
@@ -229,6 +228,7 @@ static int test_mmap_thread(void)
        pid = fork();
        if (!pid) {
                int i;
+               char bf;
 
                read(go_pipe[0], &bf, 1);
 
@@ -266,7 +266,7 @@ static int test_mmap_thread(void)
        perf_evlist__enable(evlist);
 
        /* kick the child and wait for it to finish */
-       write(go_pipe[1], &bf, 1);
+       write(go_pipe[1], "A", 1);
        waitpid(pid, NULL, 0);
 
        /*
--

2.30.0.296.g2bfb1c46d8-goog

Acked-by on v1 1/1
#2 lore raw
In reply to Ian Rogers
Quoted 5 lines · Ian Rogers

The variable bf is read (for a write call) without being initialized triggering a memory sanitizer warning. Use bf in the read and switch the write to reading from a string.

thanks,
jirka

Quoted 36 lines
---
 tools/lib/perf/tests/test-evlist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/perf/tests/test-evlist.c +2 -2
index 6d8ebe0c2504..1b225fe34a72 100644
@@ -208,7 +208,6 @@ static int test_mmap_thread(void)
 	char path[PATH_MAX];
 	int id, err, pid, go_pipe[2];
 	union perf_event *event;
-	char bf;
 	int count = 0;
 
 	snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
@@ -229,6 +228,7 @@ static int test_mmap_thread(void)
 	pid = fork();
 	if (!pid) {
 		int i;
+		char bf;
 
 		read(go_pipe[0], &bf, 1);
 
@@ -266,7 +266,7 @@ static int test_mmap_thread(void)
 	perf_evlist__enable(evlist);
 
 	/* kick the child and wait for it to finish */
-	write(go_pipe[1], &bf, 1);
+	write(go_pipe[1], "A", 1);
 	waitpid(pid, NULL, 0);
 
 	/*
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
maintainer Applied
#3 lore raw
In reply to Ian Rogers

Em Thu, Jan 14, 2021 at 01:23:04PM -0800, Ian Rogers escreveu:

Quoted 5 lines

The variable bf is read (for a write call) without being initialized triggering a memory sanitizer warning. Use bf in the read and switch the write to reading from a string.

Thanks, applied.

- Arnaldo

Quoted 36 lines
---
 tools/lib/perf/tests/test-evlist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/perf/tests/test-evlist.c +2 -2
index 6d8ebe0c2504..1b225fe34a72 100644
@@ -208,7 +208,6 @@ static int test_mmap_thread(void)
 	char path[PATH_MAX];
 	int id, err, pid, go_pipe[2];
 	union perf_event *event;
-	char bf;
 	int count = 0;
 
 	snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
@@ -229,6 +228,7 @@ static int test_mmap_thread(void)
 	pid = fork();
 	if (!pid) {
 		int i;
+		char bf;
 
 		read(go_pipe[0], &bf, 1);
 
@@ -266,7 +266,7 @@ static int test_mmap_thread(void)
 	perf_evlist__enable(evlist);
 
 	/* kick the child and wait for it to finish */
-	write(go_pipe[1], &bf, 1);
+	write(go_pipe[1], "A", 1);
 	waitpid(pid, NULL, 0);
 
 	/*
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
Signature · 1 line
- Arnaldo