]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virJSONValueToString: bail out early on error
authorJán Tomko <jtomko@redhat.com>
Tue, 2 Apr 2019 21:59:38 +0000 (23:59 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 3 Apr 2019 11:30:47 +0000 (13:30 +0200)
Now that we do not need to cater to YAJL 1, move the check for the
return value of yajl_gen_alloc earlier, so that we can assume it
was successful in later code.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virjson.c

index 857ee2395179fc36d2d277315a1eba72be5f3905..bb4052ba8161b472728454235d1980681549b540 100644 (file)
@@ -1941,16 +1941,14 @@ virJSONValueToBuffer(virJSONValuePtr object,
     VIR_DEBUG("object=%p", object);
 
     g = yajl_gen_alloc(NULL);
-    if (g) {
-        yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
-        yajl_gen_config(g, yajl_gen_indent_string, pretty ? "  " : " ");
-        yajl_gen_config(g, yajl_gen_validate_utf8, 1);
-    }
     if (!g) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to create JSON formatter"));
         goto cleanup;
     }
+    yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
+    yajl_gen_config(g, yajl_gen_indent_string, pretty ? "  " : " ");
+    yajl_gen_config(g, yajl_gen_validate_utf8, 1);
 
     if (virJSONValueToStringOne(object, g) < 0) {
         virReportOOMError();