From: Jiri Olsa <jolsa@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf parse-events: Use asprintf() instead of strncpy() for tracepoints
Date: Mon, 2 Mar 2020 16:27:41 +0100 [thread overview]
Message-ID: <20200302152741.GA263077@krava> (raw)
In-Reply-To: <20200302145535.GA28183@kernel.org>
On Mon, Mar 02, 2020 at 11:55:35AM -0300, Arnaldo Carvalho de Melo wrote:
SNIP
> | ^~~~~~
> CC /tmp/build/perf/util/call-path.o
>
> So I replaced it with asprintf to make the code shorter, use a bit less
> memory and deal with the above problem, ok?
>
> - Arnaldo
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index c01ba6f8fdad..a14995835d85 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -257,21 +257,15 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
> path = zalloc(sizeof(*path));
> if (!path)
> return NULL;
> - path->system = malloc(MAX_EVENT_LENGTH);
> - if (!path->system) {
> + if (asprintf(&path->system, "%.*s", MAX_EVENT_LENGTH, sys_dirent->d_name) < 0) {
> free(path);
> return NULL;
> }
> - path->name = malloc(MAX_EVENT_LENGTH);
> - if (!path->name) {
> + if (asprintf(&path->name, "%.*s", MAX_EVENT_LENGTH, evt_dirent->d_name) < 0) {
> zfree(&path->system);
> free(path);
> return NULL;
> }
> - strncpy(path->system, sys_dirent->d_name,
> - MAX_EVENT_LENGTH);
> - strncpy(path->name, evt_dirent->d_name,
> - MAX_EVENT_LENGTH);
looks good to me, and we can probably remove MAX_EVENT_LENGTH as well?
jirka
next prev parent reply other threads:[~2020-03-02 15:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-02 14:55 [PATCH] perf parse-events: Use asprintf() instead of strncpy() for tracepoints Arnaldo Carvalho de Melo
2020-03-02 15:27 ` Jiri Olsa [this message]
2020-03-02 18:27 ` Arnaldo Carvalho de Melo
2020-03-04 11:01 ` [tip: perf/urgent] perf parse-events: Use asprintf() instead of strncpy() to read tracepoint files tip-bot2 for Arnaldo Carvalho de Melo
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=20200302152741.GA263077@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.