From: Scott Feldman <scofeldm@cisco.com>
To: Julia Lawall <julia@diku.dk>, Joe Eykholt <jeykholt@cisco.com>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
Date: Mon, 16 Nov 2009 15:46:25 -0800 [thread overview]
Message-ID: <C7272451.17157%scofeldm@cisco.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0911120848100.16627@ask.diku.dk>
Thanks Julia/Jorg. We'll pick up change in next enic patch series.
-scott
On 11/11/09 11:48 PM, "Julia Lawall" <julia@diku.dk> wrote:
> From: Julia Lawall <julia@diku.dk>
>
> As observed by Joe Perches, sizeof of a constant string includes the
> trailing 0. If what is wanted is to check the initial characters of
> another string, this trailing 0 should not be taken into account. If an
> exact match is wanted, strcmp should be used instead.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression foo;
> constant char *abc;
> @@
>
> strncmp(foo, abc,
> - sizeof(abc)
> + sizeof(abc)-1
> )
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
>
> ---
> drivers/net/enic/vnic_dev.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff -u -p a/drivers/net/enic/vnic_dev.c b/drivers/net/enic/vnic_dev.c
> --- a/drivers/net/enic/vnic_dev.c
> +++ b/drivers/net/enic/vnic_dev.c
> @@ -358,9 +358,9 @@ int vnic_dev_hw_version(struct vnic_dev
> if (err)
> return err;
>
> - if (strncmp(fw_info->hw_version, "A1", sizeof("A1")) == 0)
> + if (strncmp(fw_info->hw_version, "A1", sizeof("A1") - 1) == 0)
> *hw_ver = VNIC_DEV_HW_VER_A1;
> - else if (strncmp(fw_info->hw_version, "A2", sizeof("A2")) == 0)
> + else if (strncmp(fw_info->hw_version, "A2", sizeof("A2") - 1) == 0)
> *hw_ver = VNIC_DEV_HW_VER_A2;
> else
> *hw_ver = VNIC_DEV_HW_VER_UNKNOWN;
prev parent reply other threads:[~2009-11-16 23:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-12 7:48 [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp Julia Lawall
2009-11-12 10:05 ` Jörg-Volker Peetz
2009-11-12 10:17 ` Jörg-Volker Peetz
2009-11-16 23:46 ` Scott Feldman [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=C7272451.17157%scofeldm@cisco.com \
--to=scofeldm@cisco.com \
--cc=jeykholt@cisco.com \
--cc=julia@diku.dk \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.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 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).