All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp
@ 2009-11-12  7:49 ` Julia Lawall
  0 siblings, 0 replies; 22+ messages in thread
From: Julia Lawall @ 2009-11-12  7:49 UTC (permalink / raw)
  To: al, 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>

---
 fs/qnx4/inode.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index 449f5a6..0614b00 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -221,7 +221,9 @@ static const char *qnx4_checkroot(struct super_block *sb)
 				rootdir = (struct qnx4_inode_entry *) (bh->b_data + i * QNX4_DIR_ENTRY_SIZE);
 				if (rootdir->di_fname != NULL) {
 					QNX4DEBUG((KERN_INFO "rootdir entry found : [%s]\n", rootdir->di_fname));
-					if (!strncmp(rootdir->di_fname, QNX4_BMNAME, sizeof QNX4_BMNAME)) {
+					if (!strncmp(rootdir->di_fname,
+						     QNX4_BMNAME,
+						     sizeof QNX4_BMNAME - 1)) {
 						found = 1;
 						qnx4_sb(sb)->BitMap = kmalloc( sizeof( struct qnx4_inode_entry ), GFP_KERNEL );
 						if (!qnx4_sb(sb)->BitMap) {

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2009-12-18 14:26 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-12  7:49 [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp Julia Lawall
2009-11-12  7:49 ` Julia Lawall
2009-11-12  9:25 ` Anders Larsen
2009-11-12  9:25   ` Anders Larsen
2009-11-12 10:05   ` Julia Lawall
2009-11-12 10:05     ` Julia Lawall
2009-11-12 10:14   ` Julia Lawall
2009-11-12 10:14     ` Julia Lawall
2009-11-12 10:22 ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof Bernd Petrovitsch
2009-11-12 10:22   ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp) Bernd Petrovitsch
2009-11-12 10:37   ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof Julia Lawall
2009-11-12 10:37     ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp) Julia Lawall
2009-11-12 15:33   ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof Julia Lawall
2009-11-12 15:33     ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp) Julia Lawall
2009-11-13 16:42     ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement Bernd Petrovitsch
2009-11-13 16:42       ` sizeof vs strlen (was Re: [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp) Bernd Petrovitsch
2009-11-12 22:08 ` [PATCH 4/4] fs/qnx4: decrement sizeof size in strncmp Anders Larsen
2009-11-12 22:08   ` Anders Larsen
2009-12-18 14:26   ` Jiri Kosina
2009-12-18 14:26     ` Jiri Kosina
2009-11-12 23:49 ` David Wagner
2009-11-13  0:06   ` Joe Perches

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.