WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH V6 2/3] libxl: Introduce JSON parsing stuff.

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.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [Xen-devel] [PATCH V6 2/3] libxl: Introduce JSON parsing stuff., Ian Jackson <=