From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJYMk-0007K1-2S for qemu-devel@nongnu.org; Wed, 13 Jan 2016 22:14:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJYMj-0005mF-6y for qemu-devel@nongnu.org; Wed, 13 Jan 2016 22:14:26 -0500 Date: Thu, 14 Jan 2016 11:14:15 +0800 From: Fam Zheng Message-ID: <20160114031415.GB8550@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: Alberto Garcia Cc: Kevin Wolf , qemu-devel@nongnu.org, qemu-block@nongnu.org, Markus Armbruster On Wed, 01/13 12:13, Alberto Garcia wrote: > 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. Those callers rely on casting preserves the MSB as the sign, but that's ugly. Anyway I'd leave the API change for a separate series and keep this patch local to fix this particular regression. :) Fam