From: Ian Jackson Subject: Re: [PATCH V6 2/3] libxl: Introduce JSON parsing stuff. Date: Tue, 5 Jul 2011 18:21:04 +0100 Message-ID: <19987.18432.53651.770280@mariner.uk.xensource.com> References: <1309455045-3062-1-git-send-email-anthony.perard@citrix.com> <1309455045-3062-3-git-send-email-anthony.perard@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1309455045-3062-3-git-send-email-anthony.perard@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Anthony PERARD Cc: Ian Campbell , Xen Devel , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Anthony PERARD writes ("[Xen-devel] [PATCH V6 2/3] libxl: Introduce JSON parsing stuff."): > +static int json_object_append_to(libxl_ctx *ctx, > + libxl__json_object *obj, > + libxl__json_object *dst) > +{ > + if (!dst) { > + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, > + "No parent json object to fill"); > + return -1; > + } Surely it is fair enough for this function to dereference NULL (and segfault) if dst==0 ? Returning -1 (ie, operational error similar to memory allocation failure) for a programming mistake like that is not a good idea IMO. > +static int json_callback_string(void *opaque, const unsigned char *str, > + unsigned int len) > +{ > + libxl__yajl_ctx *ctx = opaque; > + char *t = malloc(len + 1); > + libxl__json_object *obj = NULL; > + > + if (t == NULL) { > + LIBXL__LOG_ERRNO(ctx->ctx, LIBXL__LOG_ERROR, "Failed to allocate"); > + return 0; > + } This separation of the allocation from the test is pretty nasty. Thanks, Ian.