X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=jshn.c;h=69cb06f91f75058fecfc9da92c05646398baad0d;hp=cd9d402523f2e8c6c5cad9805e65adb7b221399e;hb=ad9b5a387df86c3fa1bdf733b913f5bf4b751f21;hpb=d59fa8d58844f3d6fad70a540a73ee6290613dd4 diff --git a/jshn.c b/jshn.c index cd9d402..69cb06f 100644 --- a/jshn.c +++ b/jshn.c @@ -258,18 +258,31 @@ static int jshn_format(bool no_newline, bool indent) { json_object *obj; const char *output; + char *blobmsg_output = NULL; + int ret = -1; + + if (!(obj = json_object_new_object())) + return -1; + + jshn_add_objects(obj, "J_V", false); + if (!(output = json_object_to_json_string(obj))) + goto out; - obj = json_object_new_object(); - jshn_add_objects(obj, "JSON_VAR", false); - output = json_object_to_json_string(obj); if (indent) { blob_buf_init(&b, 0); - blobmsg_add_json_from_string(&b, output); - output = blobmsg_format_json_indent(b.head, 1, 0); + if (!blobmsg_add_json_from_string(&b, output)) + goto out; + if (!(blobmsg_output = blobmsg_format_json_indent(b.head, 1, 0))) + goto out; + output = blobmsg_output; } fprintf(stdout, "%s%s", output, no_newline ? "" : "\n"); + free(blobmsg_output); + ret = 0; + +out: json_object_put(obj); - return 0; + return ret; } static int usage(const char *progname)