Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1391204

[RFC PATCH 6/8] perf pmu: Make pmu_formats_string to check return value of strbuf

From Masami Hiramatsu <mhiramat@kernel.org>
Newsgroups linux.kernel
Subject [RFC PATCH 6/8] perf pmu: Make pmu_formats_string to check return value of strbuf
Date 2016-04-29 16:50 +0200
Message-ID <rthTZ-7HC-39@gated-at.bofh.it> (permalink)
References <rthTY-7HC-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Make pmu_formats_string() to check return value of
strbuf APIs so that it can detect errors in it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/pmu.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index bf34468..ddb0261 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -643,20 +643,20 @@ static int pmu_resolve_param_term(struct parse_events_term *term,
 static char *pmu_formats_string(struct list_head *formats)
 {
 	struct perf_pmu_format *format;
-	char *str;
-	struct strbuf buf;
+	char *str = NULL;
+	struct strbuf buf = STRBUF_INIT;
 	unsigned i = 0;
 
 	if (!formats)
 		return NULL;
 
-	strbuf_init(&buf, 0);
 	/* sysfs exported terms */
 	list_for_each_entry(format, formats, list)
-		strbuf_addf(&buf, i++ ? ",%s" : "%s",
-			    format->name);
+		if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0)
+			goto error;
 
 	str = strbuf_detach(&buf, NULL);
+error:
 	strbuf_release(&buf);
 
 	return str;

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH 0/8] perf tools: Update strbuf to remove xrealloc Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-29 16:50 +0200
  [RFC PATCH 3/8] perf help: Make check_emacsclient_version to check strbuf APIs Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-29 16:50 +0200
  [RFC PATCH 1/8] perf: Rewrite strbuf not to die Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-29 16:50 +0200
  [RFC PATCH 6/8] perf pmu: Make pmu_formats_string to check return value of strbuf Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-29 16:50 +0200
  [RFC PATCH 4/8] perf: Make alias handler to check return value of strbuf Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-29 16:50 +0200
  Re: [RFC PATCH 0/8] perf tools: Update strbuf to remove xrealloc Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-29 17:00 +0200
    Re: [RFC PATCH 0/8] perf tools: Update strbuf to remove xrealloc Masami Hiramatsu <mhiramat@kernel.org> - 2016-04-29 17:20 +0200

csiph-web