[libvirt] [PATCH 07/10] virJSONValueToString: bail out early on error

Ján Tomko posted 10 patches 6 years, 8 months ago
[libvirt] [PATCH 07/10] virJSONValueToString: bail out early on error
Posted by Ján Tomko 6 years, 8 months ago
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>
---
 src/util/virjson.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index b163d5c1cb..91ce97a689 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1939,16 +1939,14 @@ virJSONValueToString(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();
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 07/10] virJSONValueToString: bail out early on error
Posted by Daniel P. Berrangé 6 years, 8 months ago
On Wed, Apr 03, 2019 at 07:40:22AM +0200, Ján Tomko wrote:
> 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>
> ---
>  src/util/virjson.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list