From: Jiri Olsa <jolsa@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: Re: perf: Use strcmp(str, "const") instead of strncmp(str, "const", sizeof("const"))
Date: Tue, 1 Jan 2019 19:00:51 +0100 [thread overview]
Message-ID: <20190101180051.GB9613@krava> (raw)
In-Reply-To: <20181220185553.GA22971@kernel.org>
On Thu, Dec 20, 2018 at 03:55:53PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Dec 20, 2018 at 12:26:01PM -0500, Steven Rostedt escreveu:
> > As strncmp(str, "const", sizeof("const") is exactly the same as
> > strcmp(str, "const") use that instead, otherwise it is confusing.
> >
> > sizeof("const") includes the nul terminator ('\0') of the string
> > "const", and that means strncmp() will only return a match if str and
> > "const" are exactly the same, which is what strcmp() does.
>
> There are more of those, that are there from time immemorial, lemme see
> if the original intention can be found...
>
> commit 26d330226b9cf6208daae9b0b3697980c8fb51d8
> Author: Jiri Olsa <jolsa@redhat.com>
> Date: Tue Aug 7 15:20:47 2012 +0200
>
> perf tools: Support for DWARF mode callchain
>
> ----------------
>
> I thought this could be because at the time strchr was used and thus the
> name would be in a buffer followed by ',' or other separator, but
> strtok_r() was used, so your patch should simplify things.
yea, strtok_r returns null-terminated string containing the next token,
so there's always trailing null terminator.. so those strncmp calls
work properly
jirka
prev parent reply other threads:[~2019-01-01 18:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-20 17:26 perf: Use strcmp(str, "const") instead of strncmp(str, "const", sizeof("const")) Steven Rostedt
2018-12-20 18:55 ` Arnaldo Carvalho de Melo
2019-01-01 18:00 ` Jiri Olsa [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=20190101180051.GB9613@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@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