From bae39ea87133aed886699a423a7ccce2a8f8fd32 Mon Sep 17 00:00:00 2001 From: Jia Zhou Date: Thu, 29 Jul 2021 17:39:18 +0200 Subject: [PATCH] virnvme: Duplicate index in nested loop in virNVMeDeviceListCreateReAttachList When loop in function virNVMeDeviceListCreateReAttachList() there may be reused index @i, this patch fix this by using a new @j. Signed-off-by: Jia Zhou Signed-off-by: Yi Wang Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/util/virnvme.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virnvme.c b/src/util/virnvme.c index 0eda36aa6d..11da76e760 100644 --- a/src/util/virnvme.c +++ b/src/util/virnvme.c @@ -397,12 +397,13 @@ virNVMeDeviceListCreateReAttachList(virNVMeDeviceList *activeList, const virNVMeDevice *d = toReAttachList->devs[i]; g_autoptr(virPCIDevice) pci = NULL; size_t nused = 0; + size_t j; /* Check if there is any other NVMe device with the same PCI address as * @d. To simplify this, let's just count how many NVMe devices with * the same PCI address there are on the @activeList. */ - for (i = 0; i < activeList->count; i++) { - virNVMeDevice *other = activeList->devs[i]; + for (j = 0; j < activeList->count; j++) { + virNVMeDevice *other = activeList->devs[j]; if (!virPCIDeviceAddressEqual(&d->address, &other->address)) continue;