From owner-freebsd-bugs@FreeBSD.ORG Tue Jan 19 13:20:05 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 46BFA106566C for ; Tue, 19 Jan 2010 13:20:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 2E8B68FC16 for ; Tue, 19 Jan 2010 13:20:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o0JDK4el045159 for ; Tue, 19 Jan 2010 13:20:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o0JDK43Q045158; Tue, 19 Jan 2010 13:20:04 GMT (envelope-from gnats) Date: Tue, 19 Jan 2010 13:20:04 GMT Message-Id: <201001191320.o0JDK43Q045158@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Cc: Subject: Re: bin/142911: [patch] vmstat(8) -w should produce error message if fed a negative value X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2010 13:20:05 -0000 The following reply was made to PR bin/142911; it has been noted by GNATS. From: Bruce Evans To: Efstratios Karatzas Cc: bug-followup@FreeBSD.org, Bruce Evans 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