]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: json: Improve handling and docs for adding JSON objects
authorPeter Krempa <pkrempa@redhat.com>
Tue, 23 Sep 2014 09:48:08 +0000 (11:48 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 15 Oct 2014 08:27:50 +0000 (10:27 +0200)
The JSON structure constructor has an option to add JSON arrays to the
constructed object. The description is inaccurate as it can add any json
object even a dict. Change the docs to cover this option and reject
adding NULL objects.

src/util/virjson.c

index 1dedd8fe0c97982278bbe9474a2d5ab2587c6301..81833f73a7a39e29ea5bcdef079fca4bbb33d321 100644 (file)
@@ -97,7 +97,8 @@ struct _virJSONParser {
  *
  * d: double precision floating point number
  * n: json null value
- * a: json array
+ *
+ * a: json object, must be non-NULL
  *
  * The value corresponds to the selected type.
  *
@@ -231,6 +232,14 @@ virJSONValueObjectCreateVArgs(virJSONValuePtr *obj, va_list args)
 
         case 'a': {
             virJSONValuePtr val = va_arg(args, virJSONValuePtr);
+
+            if (!val) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("argument key '%s' must not have null value"),
+                               key);
+                goto cleanup;
+            }
+
             rc = virJSONValueObjectAppend(jargs, key, val);
         }   break;