Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jan 2010 23:48:21 +0200
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r201773 - head/sys/fs/tmpfs
Message-ID:  <20100108214821.GA985@a91-153-117-195.elisa-laajakaista.fi>
In-Reply-To: <20100109051536.R57595@delplex.bde.org>
References:  <201001080757.o087vhrr009799@svn.freebsd.org> <20100109051536.R57595@delplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help

Thank you for looking at this.

On 2010-01-09, Bruce Evans wrote:
> The current incorrect way is to use %d.  Since ino_t happens to have
> type uint32_t and u_int happens to have type uint32_t on all supported
> machines, %u would work but %d gives undefined behaviour when the
> value exceeds INT_MAX.
> 
> The simplest fix is to use u_int and %u.
> 
> > +	u_quad_t	size_max;
> 
> Even larger indentation error, as above.

Does following patch look reasonable?

- Fix style bugs introduced in r201773.
- Change the type of nodes_max to u_int and use "%u" format string to
  convert its value.

%%%
Index: sys/fs/tmpfs/tmpfs_vfsops.c
===================================================================
--- sys/fs/tmpfs/tmpfs_vfsops.c	(revision 201818)
+++ sys/fs/tmpfs/tmpfs_vfsops.c	(working copy)
@@ -185,8 +185,8 @@ tmpfs_mount(struct mount *mp)
 	ino_t nodes;
 	int error;
 	/* Size counters. */
-	ino_t		nodes_max;
-	u_quad_t	size_max;
+	u_int nodes_max;
+	u_quad_t size_max;
 
 	/* Root node attributes. */
 	uid_t	root_uid;
@@ -223,7 +223,7 @@ tmpfs_mount(struct mount *mp)
 	if (mp->mnt_cred->cr_ruid != 0 ||
 	    vfs_scanopt(mp->mnt_optnew, "mode", "%ho", &root_mode) != 1)
 		root_mode = va.va_mode;
-	if (vfs_scanopt(mp->mnt_optnew, "inodes", "%d", &nodes_max) != 1)
+	if (vfs_scanopt(mp->mnt_optnew, "inodes", "%u", &nodes_max) != 1)
 		nodes_max = 0;
 	if (vfs_scanopt(mp->mnt_optnew, "size", "%qu", &size_max) != 1)
 		size_max = 0;
@@ -239,7 +239,7 @@ tmpfs_mount(struct mount *mp)
 	 * allowed to use, based on the maximum size the user passed in
 	 * the mount structure.  A value of zero is treated as if the
 	 * maximum available space was requested. */
-	if (size_max < PAGE_SIZE || size_max > (SIZE_MAX - PAGE_SIZE))
+	if (size_max < PAGE_SIZE || size_max > SIZE_MAX - PAGE_SIZE)
 		pages = SIZE_MAX;
 	else
 		pages = howmany(size_max, PAGE_SIZE);
%%%

-- 
Jaakko



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100108214821.GA985>