Like commit 94a26c7e from Eric Blake, the old fuzzy code should be replaced by the new array management macros now. And the type of scsi->count should be changed into "size_t", and thus virSCSIDeviceListCount should return size_t instead, similar for vir{PCI,USB}DeviceListCount. --- src/util/virpci.c | 2 +- src/util/virpci.h | 2 +- src/util/virscsi.c | 35 ++++++++++------------------------- src/util/virscsi.h | 2 +- src/util/virusb.c | 2 +- src/util/virusb.h | 2 +- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 8ec642f..ea93771 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1721,7 +1721,7 @@ virPCIDeviceListGet(virPCIDeviceListPtr list, return list->devs[idx]; } -int +size_t virPCIDeviceListCount(virPCIDeviceListPtr list) { return list->count; diff --git a/src/util/virpci.h b/src/util/virpci.h index 0479f0b..08bf4c3 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -86,7 +86,7 @@ int virPCIDeviceListAdd(virPCIDeviceListPtr list, int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev); virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list, int idx); -int virPCIDeviceListCount(virPCIDeviceListPtr list); +size_t virPCIDeviceListCount(virPCIDeviceListPtr list); virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list, virPCIDevicePtr dev); virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list, diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 7aca9e6..f12a2a5 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -62,7 +62,7 @@ struct _virSCSIDevice { struct _virSCSIDeviceList { virObjectLockable parent; - unsigned int count; + size_t count; virSCSIDevicePtr *devs; }; @@ -356,12 +356,7 @@ virSCSIDeviceListAdd(virSCSIDeviceListPtr list, return -1; } - if (VIR_REALLOC_N(list->devs, list->count + 1) < 0) - return -1; - - list->devs[list->count++] = dev; - - return 0; + return VIR_APPEND_ELEMENT(list->devs, list->count, dev); } virSCSIDevicePtr @@ -373,7 +368,7 @@ virSCSIDeviceListGet(virSCSIDeviceListPtr list, int idx) return list->devs[idx]; } -int +size_t virSCSIDeviceListCount(virSCSIDeviceListPtr list) { return list->count; @@ -387,24 +382,14 @@ virSCSIDeviceListSteal(virSCSIDeviceListPtr list, size_t i; for (i = 0; i < list->count; i++) { - if (list->devs[i]->adapter != dev->adapter || - list->devs[i]->bus != dev->bus || - list->devs[i]->target != dev->target || - list->devs[i]->unit != dev->unit) - continue; - - ret = list->devs[i]; - - if (i != list->count--) - memmove(&list->devs[i], - &list->devs[i+1], - sizeof(*list->devs) * (list->count - i)); - - if (VIR_REALLOC_N(list->devs, list->count) < 0) { - ; /* not fatal */ + if (list->devs[i]->adapter == dev->adapter || + list->devs[i]->bus == dev->bus || + list->devs[i]->target == dev->target || + list->devs[i]->unit == dev->unit) { + ret = list->devs[i]; + VIR_DELETE_ELEMENT(list->devs, i, list->count); + break; } - - break; } return ret; diff --git a/src/util/virscsi.h b/src/util/virscsi.h index cce5df4..4c461f8 100644 --- a/src/util/virscsi.h +++ b/src/util/virscsi.h @@ -77,7 +77,7 @@ int virSCSIDeviceListAdd(virSCSIDeviceListPtr list, virSCSIDevicePtr dev); virSCSIDevicePtr virSCSIDeviceListGet(virSCSIDeviceListPtr list, int idx); -int virSCSIDeviceListCount(virSCSIDeviceListPtr list); +size_t virSCSIDeviceListCount(virSCSIDeviceListPtr list); virSCSIDevicePtr virSCSIDeviceListSteal(virSCSIDeviceListPtr list, virSCSIDevicePtr dev); void virSCSIDeviceListDel(virSCSIDeviceListPtr list, diff --git a/src/util/virusb.c b/src/util/virusb.c index 3c82200..bb5980d 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -464,7 +464,7 @@ virUSBDeviceListGet(virUSBDeviceListPtr list, return list->devs[idx]; } -int +size_t virUSBDeviceListCount(virUSBDeviceListPtr list) { return list->count; diff --git a/src/util/virusb.h b/src/util/virusb.h index aa59d12..e0a7c4c 100644 --- a/src/util/virusb.h +++ b/src/util/virusb.h @@ -86,7 +86,7 @@ int virUSBDeviceListAdd(virUSBDeviceListPtr list, virUSBDevicePtr dev); virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list, int idx); -int virUSBDeviceListCount(virUSBDeviceListPtr list); +size_t virUSBDeviceListCount(virUSBDeviceListPtr list); virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list, virUSBDevicePtr dev); void virUSBDeviceListDel(virUSBDeviceListPtr list, -- 1.8.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list