From c087402082daa56d2141208e404f8a38b7569a2b Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Wed, 24 Aug 2016 16:11:02 -0400 Subject: [PATCH] qemu: cap: Refactor access to array in virQEMUCapsProbeQMPMachineTypes https://bugzilla.redhat.com/show_bug.cgi?id=1097930 https://bugzilla.redhat.com/show_bug.cgi?id=1224341 Use a temporary pointer rather than always recalculating the index in a very verbose way. (cherry picked from commit e44cdaf80b3af528a7b9ab5b555cd09cd27b3f1e) --- src/qemu/qemu_capabilities.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f6a42e7..49ad9df 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2485,18 +2485,20 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, goto cleanup; for (i = 0; i < nmachines; i++) { + struct virQEMUCapsMachineType *mach; if (STREQ(machines[i]->name, "none")) continue; - qemuCaps->nmachineTypes++; - if (VIR_STRDUP(qemuCaps->machineTypes[qemuCaps->nmachineTypes -1].alias, - machines[i]->alias) < 0 || - VIR_STRDUP(qemuCaps->machineTypes[qemuCaps->nmachineTypes - 1].name, - machines[i]->name) < 0) + + mach = &(qemuCaps->machineTypes[qemuCaps->nmachineTypes++]); + + if (VIR_STRDUP(mach->alias, machines[i]->alias) < 0 || + VIR_STRDUP(mach->name, machines[i]->name) < 0) goto cleanup; + + mach->maxCpus = machines[i]->maxCpus; + if (machines[i]->isDefault) defIdx = qemuCaps->nmachineTypes - 1; - qemuCaps->machineTypes[qemuCaps->nmachineTypes - 1].maxCpus = - machines[i]->maxCpus; } if (defIdx) -- 2.10.0