The glib implementation doesn't tolerate NULL but in most cases we check
before anyways. The rest of the callers adds a NULL check.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/cpu/cpu_arm.c | 2 +-
src/qemu/qemu_conf.c | 4 ++--
src/qemu/qemu_firmware.c | 5 ++++-
src/qemu/qemu_vhost_user.c | 4 +++-
src/util/virprocess.c | 3 ++-
src/util/virstring.c | 4 ++--
tests/virconftest.c | 4 ++--
tests/virstringtest.c | 6 +++---
tools/virsh-completer.c | 2 +-
tools/virsh-domain.c | 2 +-
tools/virsh-host.c | 4 ++--
tools/virt-login-shell-helper.c | 2 +-
tools/vsh.c | 2 +-
13 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index 6ba5bf0724..a7aef29fe4 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -637,7 +637,7 @@ virCPUarmDecode(virCPUDefPtr cpu,
cpu->vendor = g_strdup(vendor->name);
if (cpuData->features) {
- cpu->nfeatures = virStringListLength((const char **)cpuData->features);
+ cpu->nfeatures = g_strv_length(cpuData->features);
cpu->features = g_new0(virCPUFeatureDef, cpu->nfeatures);
for (i = 0; i < cpu->nfeatures; i++) {
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 35d0b6515c..2bbc75024c 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -648,7 +648,7 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfigPtr cfg,
}
VIR_FREE(cfg->hugetlbfs);
- cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs);
+ cfg->nhugetlbfs = g_strv_length(hugetlbfs);
if (hugetlbfs[0])
cfg->hugetlbfs = g_new0(virHugeTLBFS, cfg->nhugetlbfs);
@@ -847,7 +847,7 @@ virQEMUDriverConfigLoadNVRAMEntry(virQEMUDriverConfigPtr cfg,
return 0;
}
- cfg->nfirmwares = virStringListLength((const char *const *)nvram);
+ cfg->nfirmwares = g_strv_length(nvram);
cfg->firmwares = g_new0(virFirmwarePtr, cfg->nfirmwares);
for (i = 0; nvram[i] != NULL; i++) {
diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index e6541d505e..c571fdecf7 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -1191,7 +1191,10 @@ qemuFirmwareFetchParsedConfigs(bool privileged,
if (qemuFirmwareFetchConfigs(&paths, privileged) < 0)
return -1;
- npaths = virStringListLength((const char **)paths);
+ if (!paths)
+ return 0;
+
+ npaths = g_strv_length(paths);
firmwares = g_new0(qemuFirmwarePtr, npaths);
diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c
index 5ceefbe456..a9f6f3192d 100644
--- a/src/qemu/qemu_vhost_user.c
+++ b/src/qemu/qemu_vhost_user.c
@@ -250,8 +250,10 @@ qemuVhostUserFetchParsedConfigs(bool privileged,
if (qemuVhostUserFetchConfigs(&paths, privileged) < 0)
return -1;
- npaths = virStringListLength((const char **)paths);
+ if (!paths)
+ return 0;
+ npaths = g_strv_length(paths);
vus = g_new0(qemuVhostUserPtr, npaths);
for (i = 0; i < npaths; i++) {
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 0523bf9afb..4c27f9d771 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -1013,7 +1013,8 @@ int virProcessGetStartTime(pid_t pid,
tokens = virStringSplit(tmp, " ", 0);
- if (virStringListLength((const char * const *)tokens) < 20) {
+ if (!tokens ||
+ g_strv_length(tokens) < 20) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot find start time in %s"),
filename);
diff --git a/src/util/virstring.c b/src/util/virstring.c
index c0393585e2..1fd61650be 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -182,8 +182,8 @@ virStringListMerge(char ***dst,
if (!src || !*src)
return 0;
- dst_len = virStringListLength((const char **) *dst);
- src_len = virStringListLength((const char **) *src);
+ dst_len = g_strv_length(*dst);
+ src_len = g_strv_length(*src);
if (VIR_REALLOC_N(*dst, dst_len + src_len + 1) < 0)
return -1;
diff --git a/tests/virconftest.c b/tests/virconftest.c
index 8269730662..7a759db014 100644
--- a/tests/virconftest.c
+++ b/tests/virconftest.c
@@ -394,7 +394,7 @@ static int testConfParseStringList(const void *opaque G_GNUC_UNUSED)
if (virConfGetValueStringList(conf, "string_list", false, &str) <
0)
goto cleanup;
- if (virStringListLength((const char *const*)str) != 2) {
+ if (!str || g_strv_length(str) != 2) {
fprintf(stderr, "expected a 2 element list\n");
goto cleanup;
}
@@ -418,7 +418,7 @@ static int testConfParseStringList(const void *opaque G_GNUC_UNUSED)
if (virConfGetValueStringList(conf, "string", true, &str) < 0)
goto cleanup;
- if (virStringListLength((const char *const*)str) != 1) {
+ if (!str || g_strv_length(str) != 1) {
fprintf(stderr, "expected a 1 element list\n");
goto cleanup;
}
diff --git a/tests/virstringtest.c b/tests/virstringtest.c
index 9eabb5b299..238cb9d79e 100644
--- a/tests/virstringtest.c
+++ b/tests/virstringtest.c
@@ -243,10 +243,10 @@ testStringSearch(const void *opaque)
goto cleanup;
}
- if (virStringListLength((const char * const *)matches) != nmatches) {
- fprintf(stderr, "expected %zu matches on %s but got %zd
matches\n",
+ if (g_strv_length(matches) != nmatches) {
+ fprintf(stderr, "expected %zu matches on %s but got %u matches\n",
data->expectNMatches, data->str,
- virStringListLength((const char * const *)matches));
+ g_strv_length(matches));
goto cleanup;
}
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index fb42358bd0..d3923c4bc7 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -87,7 +87,7 @@ char **
virshCommaStringListComplete(const char *input,
const char **options)
{
- const size_t optionsLen = virStringListLength(options);
+ const size_t optionsLen = g_strv_length((char **) options);
g_autofree char *inputCopy = NULL;
g_auto(GStrv) inputList = NULL;
g_auto(GStrv) ret = NULL;
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 98a87dd43c..05d79a7843 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -14391,7 +14391,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd)
if (!(keys = virStringSplit(buffer, "\n", -1)))
goto cleanup;
- nkeys = virStringListLength((const char **) keys);
+ nkeys = g_strv_length(keys);
if (nkeys == 0) {
vshError(ctl, _("File %s contains no keys"), from);
goto cleanup;
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index ba524523f5..747d355456 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -1325,7 +1325,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
return false;
result = virConnectBaselineCPU(priv->conn, (const char **)list,
- virStringListLength((const char **)list),
+ g_strv_length(list),
flags);
if (result) {
@@ -1798,7 +1798,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
result = virConnectBaselineHypervisorCPU(priv->conn, emulator, arch,
machine, virttype,
(const char **)list,
- virStringListLength((const char **)list),
+ g_strv_length(list),
flags);
if (result) {
diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c
index 0522896eee..1ac02bed00 100644
--- a/tools/virt-login-shell-helper.c
+++ b/tools/virt-login-shell-helper.c
@@ -103,7 +103,7 @@ static int virLoginShellGetShellArgv(virConfPtr conf,
(*shargv)[0] = g_strdup("/bin/sh");
*shargvlen = 1;
} else {
- *shargvlen = virStringListLength((const char *const *)*shargv);
+ *shargvlen = g_strv_length(*shargv);
}
return 0;
}
diff --git a/tools/vsh.c b/tools/vsh.c
index 202bd564f7..4e76ad348a 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2704,7 +2704,7 @@ vshCompleterFilter(char ***list,
if (!list || !*list)
return -1;
- list_len = virStringListLength((const char **) *list);
+ list_len = g_strv_length(*list);
newList = g_new0(char *, list_len + 1);
for (i = 0; i < list_len; i++) {
--
2.29.2