]> xenbits.xensource.com Git - libvirt.git/commitdiff
vmx: Rework virVMXConfigScanResultsCollector slightly
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 17 Oct 2022 10:18:40 +0000 (12:18 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 16 Nov 2022 11:51:48 +0000 (12:51 +0100)
The idea here is that virVMXConfigScanResultsCollector() sets the
networks_max_index to the highest ethernet index seen. Well, the
struct member is signed int, we parse just seen index into uint
and then typecast to compare the two. This is not necessary,
because the maximum number of NICs a vSphere domain can have is
(<drumrolll/>): ten [1]. This will fit into signed int easily
anywhere.

1: https://configmax.esp.vmware.com/guest?vmwareproduct=vSphere&release=vSphere%208.0&categories=1-0

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
src/vmx/vmx.c

index d3e452e3ef83d65a9a274eb74386e14d223a31f8..c2c909506209d5f41e7a5e9ebc705341038cf9f1 100644 (file)
@@ -1324,19 +1324,19 @@ virVMXConfigScanResultsCollector(const char* name,
     const char *suffix = NULL;
 
     if ((suffix = STRCASESKIP(name, "ethernet"))) {
-        unsigned int idx;
+        int idx;
         char *p;
 
-        if (virStrToLong_uip(suffix, &p, 10, &idx) < 0 ||
-            *p != '.') {
+        if (virStrToLong_i(suffix, &p, 10, &idx) < 0 ||
+            *p != '.' || idx < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("failed to parse the index of the VMX key '%s'"),
                            name);
             return -1;
         }
 
-        if ((int)idx > results->networks_max_index)
-            results->networks_max_index = (int)idx;
+        if (idx > results->networks_max_index)
+            results->networks_max_index = idx;
     }
 
     return 0;