From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJJBq-0000hY-8j for qemu-devel@nongnu.org; Wed, 13 Jan 2016 06:02:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJJBp-0007q0-Fg for qemu-devel@nongnu.org; Wed, 13 Jan 2016 06:02:10 -0500 Date: Wed, 13 Jan 2016 19:02:00 +0800 From: Fam Zheng Message-ID: <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> 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 11:17, Alberto Garcia wrote: > On Wed 13 Jan 2016 01:52:29 AM CET, Fam Zheng wrote: > > > The implicit casting from unsigned int to double changes negative values > > into large positive numbers and accepts them. We should instead print > > an error. > > > > 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." > > > +#define THROTTLE_VALUE_MAX 1000000000000000L > > This is larger than LONG_MAX in 32-bit systems, I don't know if you need > to use LL instead. I assume a compiler will handle that okay but yes it's safer to use LL. Fam