[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200219145256.02a92ad8@gandalf.local.home>
Date: Wed, 19 Feb 2020 14:52:55 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: <zhe.he@...driver.com>
Cc: <acme@...hat.com>, <tstoyanov@...are.com>,
<hewenliang4@...wei.com>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] tools lib traceevent: Take care of return value of
asprintf
On Fri, 14 Feb 2020 21:21:21 +0800
<zhe.he@...driver.com> wrote:
> From: He Zhe <zhe.he@...driver.com>
>
> According to the API, if memory allocation wasn't possible, or some other
> error occurs, asprintf will return -1, and the contents of strp below are
> undefined.
>
> int asprintf(char **strp, const char *fmt, ...);
>
> This patch takes care of return value of asprintf to make it less error
> prone and prevent the following build warning.
>
> ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
>
> Signed-off-by: He Zhe <zhe.he@...driver.com>
> ---
> v2: directly check the return value without saving to a variable
>
> tools/lib/traceevent/parse-filter.c | 35 +++++++++++++++++++++--------------
> 1 file changed, 21 insertions(+), 14 deletions(-)
>
> diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
> index 20eed71..6cd0228 100644
> --- a/tools/lib/traceevent/parse-filter.c
> +++ b/tools/lib/traceevent/parse-filter.c
> @@ -274,8 +274,7 @@ find_event(struct tep_handle *tep, struct event_list **events,
> sys_name = NULL;
> }
>
> - ret = asprintf(®, "^%s$", event_name);
> - if (ret < 0)
> + if (asprintf(®, "^%s$", event_name) < 0)
I know Arnaldo said you don't need to save the return value for the
check, but let's just modify the asprintf() that needs checking, and
not remove those that already save it.
Thanks!
-- Steve
Powered by blists - more mailing lists