From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony PERARD Subject: Re: [PATCH V4 09/24] libxl_json: introduce parser functions for builtin types Date: Tue, 6 May 2014 16:14:53 +0100 Message-ID: <20140506151453.GI3530@perard.uk.xensource.com> References: <1398949101-23320-1-git-send-email-wei.liu2@citrix.com> <1398949101-23320-10-git-send-email-wei.liu2@citrix.com> <1399381058.3014.121.camel@kazak.uk.xensource.com> <20140506135713.GG3530@perard.uk.xensource.com> <20140506140420.GI17067@zion.uk.xensource.com> <20140506143527.GH3530@perard.uk.xensource.com> <20140506144547.GN17067@zion.uk.xensource.com> <20140506144906.GO17067@zion.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20140506144906.GO17067@zion.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.jackson@eu.citrix.com, Ian Campbell , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, May 06, 2014 at 03:49:06PM +0100, Wei Liu wrote: > On Tue, May 06, 2014 at 03:45:47PM +0100, Wei Liu wrote: > > On Tue, May 06, 2014 at 03:35:27PM +0100, Anthony PERARD wrote: > > [...] > > > > +/* Macro to generate: > > > > + * libxl__uint8_parse_json > > > > + * libxl__uint16_parse_json > > > > + * libxl__uint32_parse_json > > > > + * libxl__uint64_parse_json > > > > + */ > > > > +#define PARSE_UINT(width) \ > > > > + int libxl__uint ## width ## _parse_json(libxl__gc *gc, \ > > > > + const libxl__json_object *o,\ > > > > + void *p) \ > > > > + { \ > > > > + long long i; \ > > > > + \ > > > > + if (!libxl__json_object_is_integer(o)) \ > > > > + return ERROR_FAIL; \ > > > > + \ > > > > + i = libxl__json_object_get_integer(o); \ > > > > + \ > > > > + if (i > UINT ## width ## _MAX) \ > > > > + return ERROR_FAIL; \ > > > > > > My guest is this will always be false for uint64 and maybe for uint32. > > > The value return by get_interger can only be <= LLONG_MAX which I > > > suppose is still < UINT64_MAX. > > > > > > > I was just being lazy about it. > > > > > Also, 'i' might be < 0. > > > > > > > Phew, I knew this but somehow I thought it was OK. :-( > > > > So the two things combined, the check should be > > > > (i > 0 && i < UINT ## width ## _MAX) > > > > What do you think? 0 is also valid ;), and I think UINTX_MAX is valid too, so (i >= 0 && i <= UINT ## width ## _MAX) should do. Or: if (i < 0 || i > UINT ## width ## _MAX) return ERROR_FAIL; > > > If json contain a value > LLONG_MAX, the value will be store as a string > > > with the type number. > > > > > > > This is also true, but I coded like this on purpose. You won't be able > > to convert that string anyway because that's why it's stored as string > > in the first place. We should just return ERROR_FAIL in this case, which > > we do already with the check libxl__json_object_is_integer. > > > > Of course with the sole exception of uint64_t parser. This is a special > case that needs to be handled. Right. -- Anthony PERARD