Skip to contentSkip to conversation

tools/perf/util/machine: Return NULL instead of null-terminating

PATCH RESEND New Donald Yandt 2 participants 2 messages May 28, 2019 – May 30, 2019 perf events

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 tools/perf/util/machine: Return NULL instead of null-terminating

Return NULL instead of null-terminating version char array when fgets fails due to end-of-file or error.

---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +2 -2
index 28a9541c4..6fd877220 100644
@@ -1235,9 +1235,9 @@ static char *get_kernel_version(const char *root_dir)
 		return NULL;
 
 	tmp = fgets(version, sizeof(version), file);
-	if (!tmp)
-		*version = '\0';
 	fclose(file);
+	if (!tmp)
+		return NULL;
 
 	name = strstr(version, prefix);
 	if (!name)

--
2.20.1

#1 lore raw

[tip:perf/core] perf machine: Return NULL instead of null-terminating /proc/version array

perf machine: Return NULL instead of null-terminating /proc/version array
Commit-ID:  34b65affe18daad31fed83e50d1f3b817786a2b7
Gitweb:     https://git.kernel.org/tip/34b65affe18daad31fed83e50d1f3b817786a2b7
Author:     Donald Yandt <[email protected]>
AuthorDate: Tue, 28 May 2019 09:41:28 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 May 2019 18:37:44 -0300

perf machine: Return NULL instead of null-terminating /proc/version array

Return NULL instead of null-terminating version char array when fgets fails due to end-of-file or error.

Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Yanmin Zhang <[email protected]>
Fixes 30ba5b0e66c8 ("perf machine: Null-terminate version char array upon fgets(/proc/version) error")
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +2 -2
index f5569f005cf3..17eec39e775e 100644
@@ -1241,9 +1241,9 @@ static char *get_kernel_version(const char *root_dir)
 		return NULL;
 
 	tmp = fgets(version, sizeof(version), file);
-	if (!tmp)
-		*version = '\0';
 	fclose(file);
+	if (!tmp)
+		return NULL;
 
 	name = strstr(version, prefix);
 	if (!name)