mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 05:17:54 +03:00
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:
parent
1114cf5e7e
commit
dcd547aec1
@ -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++) {
|
||||
|
@ -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++) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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++) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user