From: Steven Rostedt <rostedt@goodmis.org>
To: <zhe.he@windriver.com>
Cc: <acme@redhat.com>, <tstoyanov@vmware.com>,
<hewenliang4@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] tools lib traceevent: Take care of return value of asprintf
Date: Wed, 19 Feb 2020 14:52:55 -0500 [thread overview]
Message-ID: <20200219145256.02a92ad8@gandalf.local.home> (raw)
In-Reply-To: <1581686481-180476-1-git-send-email-zhe.he@windriver.com>
On Fri, 14 Feb 2020 21:21:21 +0800
<zhe.he@windriver.com> wrote:
> From: He Zhe <zhe.he@windriver.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@windriver.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
prev parent reply other threads:[~2020-02-19 19:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 13:21 zhe.he
2020-02-17 15:53 ` Arnaldo Carvalho de Melo
2020-02-19 19:52 ` Steven Rostedt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200219145256.02a92ad8@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=acme@redhat.com \
--cc=hewenliang4@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tstoyanov@vmware.com \
--cc=zhe.he@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®