lkml.org 
[lkml]   [2016]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH perf/core v2 6/8] perf pmu: Make pmu_formats_string to check return value of strbuf
Em Sat, Apr 30, 2016 at 12:10:42AM +0900, Masami Hiramatsu escreveu:
> 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;

Ok, here you use STRBUF_INIT and you removed the equivalent (I guess)
call to strbuf_init(&buf, 0) below, i.e. there will be no alloc the
check.

Looks ok.

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

\
 
 \ /
  Last update: 2016-05-06 02:21    [W:0.210 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site