From: "Jörg-Volker Peetz" <jvpeetz@web.de>
To: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
Date: Thu, 12 Nov 2009 10:17:24 +0000 [thread overview]
Message-ID: <4AFBE0B4.6070904@web.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0911120848100.16627@ask.diku.dk>
Julia Lawall wrote:
> From: Julia Law all <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>
>
<snip>
How about this pattern (uses length of first argument):
strncmp(foo, abc,
- sizeof(foo)
?
--
Best regards,
Jörg-Volker.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: "Jörg-Volker Peetz" <jvpeetz@web.de>
To: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
Date: Thu, 12 Nov 2009 11:17:24 +0100 [thread overview]
Message-ID: <4AFBE0B4.6070904@web.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0911120848100.16627@ask.diku.dk>
Julia Lawall wrote:
> From: Julia Law all <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>
>
<snip>
How about this pattern (uses length of first argument):
strncmp(foo, abc,
- sizeof(foo)
?
--
Best regards,
Jörg-Volker.
next prev parent reply other threads:[~2009-11-12 10:17 UTC|newest]
Thread overview: 7+ 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 7:48 ` Julia Lawall
2009-11-12 10:05 ` Jörg-Volker Peetz
2009-11-12 10:17 ` Jörg-Volker Peetz [this message]
2009-11-12 10:17 ` Jörg-Volker Peetz
2009-11-16 23:46 ` Scott Feldman
2009-11-16 23:46 ` Scott Feldman
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=4AFBE0B4.6070904@web.de \
--to=jvpeetz@web.de \
--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 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.