Re: [PATCH 1/4] drivers/net/enic: decrement sizeof size in strncmp

From: Jörg-Volker Peetz
Date: Thu Nov 12 2009 - 05:17:44 EST


Julia Lawall wrote:
> From: Julia Law all <julia@xxxxxxx>
>
> 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 linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/