[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.