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-changelog

[Xen-changelog] [xen-unstable] libxl: libxl_json: Check the parser statu

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: libxl_json: Check the parser status before to call parse_complete
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Fri, 11 Nov 2011 04:33:13 +0000
Delivery-date: Thu, 10 Nov 2011 20:34:14 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Anthony PERARD <anthony.perard@xxxxxxxxxx>
# Date 1320410302 0
# Node ID bdbd100b28ae011fd9db40ac6fae7fc8fe2dc345
# Parent  e0b6b0e68e90c6e09c893b2905d736b0500e5e79
libxl: libxl_json: Check the parser status before to call parse_complete

Also, use goto to handle an error.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r e0b6b0e68e90 -r bdbd100b28ae tools/libxl/libxl_json.c
--- a/tools/libxl/libxl_json.c  Fri Nov 04 12:38:22 2011 +0000
+++ b/tools/libxl/libxl_json.c  Fri Nov 04 12:38:22 2011 +0000
@@ -730,6 +730,8 @@
 {
     yajl_status status;
     libxl__yajl_ctx yajl_ctx;
+    libxl__json_object *o = NULL;
+    unsigned char *str = NULL;
 
     memset(&yajl_ctx, 0, sizeof (yajl_ctx));
     yajl_ctx.gc = gc;
@@ -744,30 +746,31 @@
         yajl_ctx.hand = yajl_alloc(&callbacks, &cfg, NULL, &yajl_ctx);
     }
     status = yajl_parse(yajl_ctx.hand, (const unsigned char *)s, strlen(s));
+    if (status != yajl_status_ok)
+        goto out;
+
     status = yajl_parse_complete(yajl_ctx.hand);
+    if (status != yajl_status_ok)
+        goto out;
 
-    if (status == yajl_status_ok) {
-        libxl__json_object *o = yajl_ctx.head;
+    o = yajl_ctx.head;
 
-        DEBUG_GEN_REPORT(&yajl_ctx);
+    DEBUG_GEN_REPORT(&yajl_ctx);
 
-        yajl_ctx.head = NULL;
+    yajl_ctx.head = NULL;
 
-        yajl_ctx_free(&yajl_ctx);
-        return o;
-    } else {
-        unsigned char *str = yajl_get_error(yajl_ctx.hand, 1,
-                                            (const unsigned char *)s,
-                                            strlen(s));
+    yajl_ctx_free(&yajl_ctx);
+    return o;
 
-        LIBXL__LOG(libxl__gc_owner(gc), LIBXL__LOG_ERROR,
-                   "yajl error: %s", str);
-        yajl_free_error(yajl_ctx.hand, str);
+out:
+    str = yajl_get_error(yajl_ctx.hand, 1, (const unsigned char*)s, strlen(s));
 
-        libxl__json_object_free(gc, yajl_ctx.head);
-        yajl_ctx_free(&yajl_ctx);
-        return NULL;
-    }
+    LIBXL__LOG(libxl__gc_owner(gc), LIBXL__LOG_ERROR, "yajl error: %s", str);
+    yajl_free_error(yajl_ctx.hand, str);
+
+    libxl__json_object_free(gc, yajl_ctx.head);
+    yajl_ctx_free(&yajl_ctx);
+    return NULL;
 }
 
 static const char *yajl_gen_status_to_string(yajl_gen_status s)

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: libxl_json: Check the parser status before to call parse_complete, Xen patchbot-unstable <=