]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vboxDumpNetwork: use switch for adapterType
authorJán Tomko <jtomko@redhat.com>
Fri, 23 Feb 2018 14:01:06 +0000 (15:01 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 5 Mar 2018 11:57:47 +0000 (12:57 +0100)
Also return an error when VIR_STRDUP fails.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/vbox/vbox_common.c

index 1a413e4acade614b6fe8180c21a4bd4b8a6a8810..3bcca43d325b6e2859cd75caa80b96d2248a74ee 100644 (file)
@@ -3699,6 +3699,7 @@ vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter)
 {
     PRUint32 attachmentType = NetworkAttachmentType_Null;
     PRUint32 adapterType = NetworkAdapterType_Null;
+    const char *model = NULL;
     PRUnichar *utf16 = NULL;
     char *utf8 = NULL;
     virDomainNetDefPtr net = NULL;
@@ -3751,21 +3752,30 @@ vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter)
     }
 
     gVBoxAPI.UINetworkAdapter.GetAdapterType(adapter, &adapterType);
-    if (adapterType == NetworkAdapterType_Am79C970A) {
-        ignore_value(VIR_STRDUP(net->model, "Am79C970A"));
-    } else if (adapterType == NetworkAdapterType_Am79C973) {
-        ignore_value(VIR_STRDUP(net->model, "Am79C973"));
-    } else if (adapterType == NetworkAdapterType_I82540EM) {
-        ignore_value(VIR_STRDUP(net->model, "82540EM"));
-    } else if (adapterType == NetworkAdapterType_I82545EM) {
-        ignore_value(VIR_STRDUP(net->model, "82545EM"));
-    } else if (adapterType == NetworkAdapterType_I82543GC) {
-        ignore_value(VIR_STRDUP(net->model, "82543GC"));
-    } else if (gVBoxAPI.APIVersion >= 3000051 &&
-               adapterType == NetworkAdapterType_Virtio) {
+    switch (adapterType) {
+    case NetworkAdapterType_Am79C970A:
+        model = "Am79C970A";
+        break;
+    case NetworkAdapterType_Am79C973:
+        model = "Am79C973";
+        break;
+    case NetworkAdapterType_I82540EM:
+        model = "82540EM";
+        break;
+    case NetworkAdapterType_I82545EM:
+        model = "82545EM";
+        break;
+    case NetworkAdapterType_I82543GC:
+        model = "82543GC";
+        break;
+    case NetworkAdapterType_Virtio:
         /* Only vbox 3.1 and later support NetworkAdapterType_Virto */
-        ignore_value(VIR_STRDUP(net->model, "virtio"));
+        if (gVBoxAPI.APIVersion >= 3000051)
+            model = "virtio";
+        break;
     }
+    if (VIR_STRDUP(net->model, model) < 0)
+        goto error;
 
     gVBoxAPI.UINetworkAdapter.GetMACAddress(adapter, &utf16);
     VBOX_UTF16_TO_UTF8(utf16, &utf8);