From: Quanfa Fu <quanfafu@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tracing/eprobe: Replace snprintf with memcpy
Date: Mon, 9 Jan 2023 12:07:26 +0800 [thread overview]
Message-ID: <CAM4UoyqtOBXRD29x_M==KJtnryC87FhTs2tW65AnDxCc7XgY7g@mail.gmail.com> (raw)
In-Reply-To: <20230108225229.1cef1a67@rorschach.local.home>
Thanks, I'll check it out.
Thanks !!
On Mon, Jan 9, 2023 at 11:52 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Mon, 9 Jan 2023 11:32:13 +0800
> Quanfa Fu <quanfafu@gmail.com> wrote:
>
> > @@ -923,17 +923,17 @@ static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const ch
> >
> > p = ep->filter_str;
> > for (i = 0; i < argc; i++) {
> > - ret = snprintf(p, len, "%s ", argv[i]);
> > - if (ret < 0)
> > - goto error;
> > - if (ret > len) {
> > - ret = -E2BIG;
> > - goto error;
> > - }
> > - p += ret;
> > - len -= ret;
> > + arg_len = strlen(argv[i]);
> > + memcpy((void *)p, argv[i], arg_len);
> > +
> > + if (i == argc - 1)
> > + p[arg_len] = '\0';
> > + else
> > + p[arg_len] = ' ';
> > +
> > + p += arg_len + 1;
> > + len -= arg_len + 1;
> > }
>
> The above is too complex. I mentioned strncat() but you could still
> just keep snprintf() too, which adds the '\0';
>
> for (i = 0; i < argc; i++) {
> if (i)
> ret = snprintf(p, len, " %s", argv[i]);
> else
> ret = snprintf(p, len, "%s", argv[i]);
> p += ret;
> len -= ret;
> }
>
> -- Steve
>
> > - p[-1] = '\0';
> >
> > /*
> > * Ensure the filter string can be parsed correctly. Note, this
prev parent reply other threads:[~2023-01-09 4:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-09 3:32 [PATCH v2] tracing/eprobe: Replace snprintf with memcpy Quanfa Fu
2023-01-09 3:52 ` Steven Rostedt
2023-01-09 4:07 ` Quanfa Fu [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='CAM4UoyqtOBXRD29x_M==KJtnryC87FhTs2tW65AnDxCc7XgY7g@mail.gmail.com' \
--to=quanfafu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).