From 2f9b2c0cdd911382c6f5fb081c5c33d768f3500b Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 5 Feb 2021 17:39:52 +0100 Subject: [PATCH] Replace virStringListLength where actual lenght is not needed Some callers don't need to know the actual lenght of the list but only care whether the required element is present or the list is non-empty. Don't calculate the list length in those cases. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/lxc/lxc_native.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/storage/storage_backend_sheepdog.c | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index e68977dd99..4229a9ca7a 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -568,7 +568,7 @@ lxcNetworkParseDataIPs(const char *name, family = AF_INET6; ipparts = virStringSplit(value->str, "/", 2); - if (virStringListLength((const char * const *)ipparts) != 2 || + if (!ipparts || !ipparts[0] || !ipparts[1] || virSocketAddrParse(&ip->address, ipparts[0], family) < 0 || virStrToLong_ui(ipparts[1], NULL, 10, &ip->prefix) < 0) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b0d907fbb3..6c468632e0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17739,7 +17739,7 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, return -1; } - if (virStringListLength((const char * const *)features) == 0) + if (!features || !*features) return 0; for (i = 0; i < dom->def->nresctrls; i++) { diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index 178cfbae11..2db2384e67 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -157,8 +157,7 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool) cells = virStringSplit(lines[i], " ", 0); - if (cells != NULL && - virStringListLength((const char * const *)cells) > 2) { + if (cells != NULL && cells[0] && cells[1]) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) return -1; }