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 <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-05 17:39:52 +01:00
parent 5188c8738e
commit 2f9b2c0cdd
3 changed files with 3 additions and 4 deletions

View File

@ -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) {

View File

@ -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++) {

View File

@ -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;
}