Received: from eggs.gnu.org ([2001:4830:134:3::10]:59051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJJMm-0005Aa-Dc for qemu-devel@nongnu.org; Wed, 13 Jan 2016 06:13:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJJMi-0001et-9O for qemu-devel@nongnu.org; Wed, 13 Jan 2016 06:13:28 -0500 From: Alberto Garcia In-Reply-To: <20160113110200.GF25517@ad.usersys.redhat.com> References: <1452646350-11999-1-git-send-email-famz@redhat.com> <1452646350-11999-2-git-send-email-famz@redhat.com> <20160113110200.GF25517@ad.usersys.redhat.com> Date: Wed, 13 Jan 2016 12:13:18 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH v2 1/2] blockdev: Error out on negative throttling option values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , qemu-devel@nongnu.org, qemu-block@nongnu.org, Markus Armbruster On Wed 13 Jan 2016 12:02:00 PM CET, Fam Zheng wrote: >> > Check the number range so this case is catched and reported. >> >> I still don't know why qemu_opt_get_number() convert silently >> negative numbers into positive ones, shouldn't it just fail with an >> "invalid parameter" error? > > Because the parsing is done with strtoull(3) and unfortunately its man > page says "negative values are considered valid input and are silently > converted to the equivalent unsigned long int value." I see... parse_uint() from cutils.c handles that by making an explicit check for negative numbers. It probably makes sense to apply the same solution (or even merge the code to the extent to which it's possible). I also noticed that there's a couple of places where we're calling qemu_opt_get_number() passing -1 as default value, so maybe that API needs to be reviewed anyway. Berto