bin/103682: nfsstat(1) should use %u instead of %d to display NFS stats

Bruce Evans bde at
Tue Sep 26 13:10:26 PDT 2006

The following reply was made to PR bin/103682; it has been noted by GNATS.

From: Bruce Evans <bde at>
To: Hiroki Sato <hrs at>
Cc: FreeBSD-gnats-submit at, freebsd-bugs at
Subject: Re: bin/103682: nfsstat(1) should use %u instead of %d to display
 NFS stats
Date: Wed, 27 Sep 2006 06:04:19 +1000 (EST)

 On Wed, 27 Sep 2006, Hiroki Sato wrote:
 >> Description:
 > 	Although nfsstat(1) uses %d in printf() to display the NFS stats,
 > 	on a busy NFS server/client the stat numbers can become more than
 > 	2147483647 (2^31 - 1, 32-bit int case) and negative numbers are
 > 	printed.  The numbers should be interpreted as unsigned int, and
 > 	displayed by using %u instead.
 I prefer to keep using %d.  One extra bit only keeps things working for
 twice as long (either in uptime or code lifetime).  Overflow to negative
 values normally gives obvious garbage, but overflow to bits that aren't
 there gives garbage.
 >> How-To-Repeat:
 > 	Use nfsstat(1) on a busy NFS server/client.
 >> Fix:
 > 	A patch is attached.  Also, I think it is better to change members
 > 	in struct nfsstats/nfsrvstats from int to uint64_t or so if possible.
 The counters really are ints, so overflow at 2^31 - 1 technically gives
 undefined behaviour.
 The code lifetime for these counters as ints expired many years ago.
 They should be changed to int64_t's to avoid sign extension bugs.

More information about the freebsd-bugs mailing list