From: Chuhong Yuan <hslester96@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>, Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH 05/12] genirq/debugfs: Replace strncmp with str_has_prefix
Date: Tue, 30 Jul 2019 18:58:50 +0800 [thread overview]
Message-ID: <CANhBUQ2L71Q2j_iOUaHW7qk0BS6wwMBwmtd8N4S5mNLYHr4Dhw@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1907301113580.1738@nanos.tec.linutronix.de>
Thomas Gleixner <tglx@linutronix.de> 于2019年7月30日周二 下午5:17写道:
>
> On Mon, 29 Jul 2019, Chuhong Yuan wrote:
>
> > strncmp(str, const, len) is error-prone.
> > We had better use newly introduced
> > str_has_prefix() instead of it.
>
> Can you please provide a proper explanation why the below strncmp() is
> error prone?
>
If the size is less than 7, for example, 2, then even if buf is "tr", the
result will still be true. This is an error.
strncmp(str, const, len) is error-prone mainly because the len is easy
to be wrong.
> Just running a script and copying some boiler plate changelog saying
> 'strncmp() is error prone' does not cut it.
>
> > - if (!strncmp(buf, "trigger", size)) {
> > + if (str_has_prefix(buf, "trigger")) {
>
> Especially when the resulting code is not equivalent.
>
I think here the semantic is the comparison should only return true
when buf is "trigger".
The buf's size is 8 and the string's size is at most 7.
Since str_has_prefix()'s implementation is strncmp(str, prefix, strlen(prefix)),
here strlen(prefix) = 7, I think it satisfies the requirement.
Regards,
Chuhong
> Thanks,
>
> tglx
next prev parent reply other threads:[~2019-07-30 10:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-29 15:14 [PATCH 05/12] genirq/debugfs: Replace strncmp with str_has_prefix Chuhong Yuan
2019-07-30 9:17 ` Thomas Gleixner
2019-07-30 10:58 ` Chuhong Yuan [this message]
2019-07-30 11:13 ` Marc Zyngier
2019-07-30 11:20 ` Chuhong Yuan
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=CANhBUQ2L71Q2j_iOUaHW7qk0BS6wwMBwmtd8N4S5mNLYHr4Dhw@mail.gmail.com \
--to=hslester96@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=tglx@linutronix.de \
/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).