bin/142911: [patch] vmstat(8) -w should produce error message if fed a negative value

Bruce Evans brde at optusnet.com.au
Tue Jan 19 13:20:05 UTC 2010


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

From: Bruce Evans <brde at optusnet.com.au>
To: Efstratios Karatzas <gpf.kira at gmail.com>
Cc: bug-followup at FreeBSD.org, Bruce Evans <brde at optusnet.com.au>
Subject: Re: bin/142911: [patch] vmstat(8) -w should produce error message
 if  fed a negative value
Date: Wed, 20 Jan 2010 00:13:48 +1100 (EST)

 On Mon, 18 Jan 2010, Efstratios Karatzas wrote:
 
 > Just thought of a simpler solution
 >
 > // if it is really 0
 > if (atoi(optarg) == 0 && strncmp(optarg, "0", 1) == 0 ) {
 >      // do stuff
 > }
 
 Ugh, use strtol() (correctly) instead of that.
 
 > Prob is that the
 > "vmstat -w 0abc"
 > command would be equivalent to
 > "vmstat -w 0"
 > but I think that's acceptable.
 
 Normal error checking for strtol() would check for there being garbage
 after the number.
 
 I don't insist on using strtol() here, but it should be considered
 whenever fixing an atoi() bug.
 
 Bruce


More information about the freebsd-bugs mailing list