From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH 3/9] libxl: json string object can be NULL Date: Mon, 13 Jul 2015 11:02:27 +0100 Message-ID: <1436781747.7019.64.camel@citrix.com> References: <1436551257-28887-1-git-send-email-wei.liu2@citrix.com> <1436551257-28887-4-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZEaZF-0007Ag-61 for xen-devel@lists.xenproject.org; Mon, 13 Jul 2015 10:02:33 +0000 In-Reply-To: <1436551257-28887-4-git-send-email-wei.liu2@citrix.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: Xen-devel , Ian Jackson , Andrew Cooper List-Id: xen-devel@lists.xenproject.org On Fri, 2015-07-10 at 19:00 +0100, Wei Liu wrote: > Signed-off-by: Wei Liu Acked-by: Ian Campbell It occurs to me that since libxl__strdup can never return NULL due to allocation failure we could consider make libxl__strdup(gc, NULL) be well defined as returning NULL. > --- > tools/libxl/libxl_json.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c > index 346929a..652b3f4 100644 > --- a/tools/libxl/libxl_json.c > +++ b/tools/libxl/libxl_json.c > @@ -433,8 +433,13 @@ int libxl__string_parse_json(libxl__gc *gc, const libxl__json_object *o, > > if (libxl__json_object_is_null(o)) > *p = NULL; > - else > - *p = libxl__strdup(NOGC, libxl__json_object_get_string(o)); > + else { > + const char *s = libxl__json_object_get_string(o); > + if (!s) > + *p = NULL; > + else > + *p = libxl__strdup(NOGC, s); > + } > > return 0; > }