Date: Tue, 19 Jan 2010 13:20:04 GMT From: Bruce Evans <brde@optusnet.com.au> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/142911: [patch] vmstat(8) -w should produce error message if fed a negative value Message-ID: <201001191320.o0JDK43Q045158@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/142911; it has been noted by GNATS. From: Bruce Evans <brde@optusnet.com.au> To: Efstratios Karatzas <gpf.kira@gmail.com> Cc: bug-followup@FreeBSD.org, Bruce Evans <brde@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001191320.o0JDK43Q045158>