Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Sep 2006 06:04:19 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Hiroki Sato <hrs@freebsd.org>
Cc:        freebsd-bugs@freebsd.org, FreeBSD-gnats-submit@freebsd.org
Subject:   Re: bin/103682: nfsstat(1) should use %u instead of %d to display NFS stats
Message-ID:  <20060927055130.H84537@delplex.bde.org>
In-Reply-To: <200609261541.k8QFfhUU036509@alph.allbsd.org>

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

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.

Bruce


home | help

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