]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: agent: use GetArray to remove a check
authorJán Tomko <jtomko@redhat.com>
Mon, 5 Oct 2020 20:09:08 +0000 (22:09 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 8 Oct 2020 09:16:08 +0000 (11:16 +0200)
The error check for ValueObjectGet("return") is redundant,
qemuAgentCommand already checked for us that the reply contains
a "return" object.

It does not guarantee, that it is an array.

Use virJSONValueObjectGetArray that combines getting the object
with checking for its type and return the more helpful of
the two error messages.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
src/qemu/qemu_agent.c

index e614fdd7c416b1cbdefcd941c00ac458d61bbaa2..e7ea03f8402ef5ee5a5d79de5197345a24226076 100644 (file)
@@ -2232,13 +2232,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent,
     if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
         goto cleanup;
 
-    if (!(ret_array = virJSONValueObjectGet(reply, "return"))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("qemu agent didn't provide 'return' field"));
-        goto cleanup;
-    }
-
-    if (!virJSONValueIsArray(ret_array)) {
+    if (!(ret_array = virJSONValueObjectGetArray(reply, "return"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("qemu agent didn't return an array of interfaces"));
         goto cleanup;