Replace virStringListLength by g_strv_length

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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-05 18:03:26 +01:00
parent 1114cf5e7e
commit dcd547aec1
13 changed files with 25 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2676,7 +2676,7 @@ vshCompleterFilter(char ***list,
if (!list || !*list)
return 0;
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++) {