* [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
@ 2009-11-12 7:48 ` Julia Lawall
0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2009-11-12 7:48 UTC (permalink / raw)
To: Scott Feldman, Joe Eykholt, netdev, linux-kernel, kernel-janitors
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
@ 2009-11-12 7:48 ` Julia Lawall
0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2009-11-12 7:48 UTC (permalink / raw)
To: Scott Feldman, Joe Eykholt, netdev, linux-kernel, kernel-janitors
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
2009-11-12 7:48 ` Julia Lawall
(?)
@ 2009-11-12 10:05 ` Jörg-Volker Peetz
-1 siblings, 0 replies; 7+ messages in thread
From: Jörg-Volker Peetz @ 2009-11-12 10:05 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, kernel-janitors
Julia Lawall wrote:
<snip>
> strncmp(foo, abc,
> - sizeof(abc)
> + sizeof(abc)-1
> )
<snip>
> - 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)
<snip>
Why not use strlen(abc) instead of sizeof(abc) - 1 ?
--
Regards,
Jörg-Volker.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
2009-11-12 7:48 ` Julia Lawall
@ 2009-11-12 10:17 ` Jörg-Volker Peetz
-1 siblings, 0 replies; 7+ messages in thread
From: Jörg-Volker Peetz @ 2009-11-12 10:17 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, kernel-janitors
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
@ 2009-11-12 10:17 ` Jörg-Volker Peetz
0 siblings, 0 replies; 7+ messages in thread
From: Jörg-Volker Peetz @ 2009-11-12 10:17 UTC (permalink / raw)
To: linux-kernel; +Cc: netdev, kernel-janitors
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
2009-11-12 7:48 ` Julia Lawall
@ 2009-11-16 23:46 ` Scott Feldman
-1 siblings, 0 replies; 7+ messages in thread
From: Scott Feldman @ 2009-11-16 23:46 UTC (permalink / raw)
To: Julia Lawall, Joe Eykholt, netdev, linux-kernel, kernel-janitors
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp
@ 2009-11-16 23:46 ` Scott Feldman
0 siblings, 0 replies; 7+ messages in thread
From: Scott Feldman @ 2009-11-16 23:46 UTC (permalink / raw)
To: Julia Lawall, Joe Eykholt, netdev, linux-kernel, kernel-janitors
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-11-16 23:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2009-11-12 10:17 ` Jörg-Volker Peetz
2009-11-16 23:46 ` Scott Feldman
2009-11-16 23:46 ` Scott Feldman
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.