]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentGetInterfaceOneAddress: check for errors early
authorJán Tomko <jtomko@redhat.com>
Wed, 7 Oct 2020 12:04:04 +0000 (14:04 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 8 Oct 2020 09:16:08 +0000 (11:16 +0200)
For readability, and to ensure we do allocation when
returning 0.

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 301707b13623b95cae1e64cccc596825dc6ce083..60247e1616c207a68f97cea88e5b9b4dc358e265 100644 (file)
@@ -2073,11 +2073,9 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr,
                        _("qemu agent didn't provide 'ip-address-type'"
                          " field for interface '%s'"), name);
         return -1;
-    } else if (STREQ(type, "ipv4")) {
-        ip_addr->type = VIR_IP_ADDR_TYPE_IPV4;
-    } else if (STREQ(type, "ipv6")) {
-        ip_addr->type = VIR_IP_ADDR_TYPE_IPV6;
-    } else {
+    }
+
+    if (STRNEQ(type, "ipv4") && STRNEQ(type, "ipv6")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown ip address type '%s'"),
                        type);
@@ -2091,7 +2089,6 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr,
                          " field for interface '%s'"), name);
         return -1;
     }
-    ip_addr->addr = g_strdup(addr);
 
     if (virJSONValueObjectGetNumberUint(ip_addr_obj, "prefix",
                                         &ip_addr->prefix) < 0) {
@@ -2100,6 +2097,12 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr,
         return -1;
     }
 
+    if (STREQ(type, "ipv4"))
+        ip_addr->type = VIR_IP_ADDR_TYPE_IPV4;
+    else
+        ip_addr->type = VIR_IP_ADDR_TYPE_IPV6;
+
+    ip_addr->addr = g_strdup(addr);
     return 0;
 }