Return the number of parameters via pointer passed as argument to free up possibility to report errors. Strangely all callers actually use 'int' as type for storing the count of elements, thus this function will use the same. The function is also renamed to virTypedParamListSteal. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/admin/admin_server.c | 10 +++++++--- src/libvirt_private.syms | 2 +- src/qemu/qemu_domainjob.c | 4 +++- src/qemu/qemu_driver.c | 4 +++- src/test/test_driver.c | 4 +++- src/util/virtypedparam.c | 20 ++++++++++++++------ src/util/virtypedparam.h | 7 ++++--- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/admin/admin_server.c b/src/admin/admin_server.c index 394de0dfab..1d1ae97f2f 100644 --- a/src/admin/admin_server.c +++ b/src/admin/admin_server.c @@ -113,7 +113,8 @@ adminServerGetThreadPoolParameters(virNetServer *srv, "%s", VIR_THREADPOOL_JOB_QUEUE_DEPTH) < 0) return -1; - *nparams = virTypedParamListStealParams(paramlist, params); + if (virTypedParamListSteal(paramlist, params, nparams) < 0) + return -1; return 0; } @@ -279,7 +280,9 @@ adminClientGetInfo(virNetServerClient *client, "%s", VIR_CLIENT_INFO_SELINUX_CONTEXT) < 0) return -1; - *nparams = virTypedParamListStealParams(paramlist, params); + if (virTypedParamListSteal(paramlist, params, nparams) < 0) + return -1; + return 0; } @@ -322,7 +325,8 @@ adminServerGetClientLimits(virNetServer *srv, "%s", VIR_SERVER_CLIENTS_UNAUTH_CURRENT) < 0) return -1; - *nparams = virTypedParamListStealParams(paramlist, params); + if (virTypedParamListSteal(paramlist, params, nparams) < 0) + return -1; return 0; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f1999d0e99..b58be6aa33 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3560,7 +3560,7 @@ virTypedParamListFetch; virTypedParamListFree; virTypedParamListFromParams; virTypedParamListNew; -virTypedParamListStealParams; +virTypedParamListSteal; virTypedParamsCheck; virTypedParamsCopy; virTypedParamsDeserialize; diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 4df1af0ce7..6be48118b9 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -522,7 +522,9 @@ qemuDomainBackupJobDataToParams(virDomainJobData *jobData, virTypedParamListAddString(par, jobData->errmsg, VIR_DOMAIN_JOB_ERRMSG) < 0) return -1; - *nparams = virTypedParamListStealParams(par, params); + if (virTypedParamListSteal(par, params, nparams) < 0) + return -1; + *type = virDomainJobStatusToType(jobData->status); return 0; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b89bf176bb..9c409948f0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18459,7 +18459,9 @@ qemuDomainGetStats(virConnectPtr conn, dom->def->uuid, dom->def->id))) return -1; - tmp->nparams = virTypedParamListStealParams(params, &tmp->params); + if (virTypedParamListSteal(params, &tmp->params, &tmp->nparams) < 0) + return -1; + *record = g_steal_pointer(&tmp); return 0; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 47c74c420c..ac12488de9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9873,7 +9873,9 @@ testDomainGetStats(virConnectPtr conn, dom->def->uuid, dom->def->id))) return -1; - tmp->nparams = virTypedParamListStealParams(params, &tmp->params); + if (virTypedParamListSteal(params, &tmp->params, &tmp->nparams) < 0) + return -1; + *record = g_steal_pointer(&tmp); return 0; } diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index e03e112d1e..68698fe583 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -780,19 +780,27 @@ virTypedParamListFetch(virTypedParamList *list, } -size_t -virTypedParamListStealParams(virTypedParamList *list, - virTypedParameterPtr *params) +int +virTypedParamListSteal(virTypedParamList *list, + virTypedParameterPtr *par, + int *npar) { - size_t ret = list->npar; + size_t nparams; + + if (virTypedParamListFetch(list, par, &nparams) < 0) + return -1; - *params = g_steal_pointer(&list->par); + /* most callers expect 'int', so help them out */ + *npar = nparams; + + list->par = NULL; list->npar = 0; list->par_alloc = 0; - return ret; + return 0; } + virTypedParamList * virTypedParamListFromParams(virTypedParameterPtr *params, size_t nparams) diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index b6ad209e25..b2869173e1 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -143,9 +143,10 @@ virTypedParamListFree(virTypedParamList *list); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virTypedParamList, virTypedParamListFree); virTypedParamList *virTypedParamListNew(void); -size_t -virTypedParamListStealParams(virTypedParamList *list, - virTypedParameterPtr *params); +int +virTypedParamListSteal(virTypedParamList *list, + virTypedParameterPtr *par, + int *npar); int virTypedParamListFetch(virTypedParamList *list, -- 2.39.2