The 'virTypedParamsFilter' function can't fail and thus it never returns
negative values. Change the return type to 'size_t' and adjust callers
to not check the return value for being negative.
Adjust the docs to hilight this and also the fact that the filtered
typed param list returned via @ret is not a deep copy and thus callers
must not use the common function to free it.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/util/virtypedparam.c | 19 ++++++++++---------
src/util/virtypedparam.h | 2 +-
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 1be249d855..634385aa97 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -394,18 +394,22 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
* @ret: pointer to the returned array
*
* Filters @params retaining only the parameters named @name in the
- * resulting array @ret. Caller should free the @ret array but not
- * the items since they are pointing to the @params elements.
+ * resulting array @ret.
*
- * Returns amount of elements in @ret on success, -1 on error.
+ * Important Caller should free the @ret array but not the items since they are
+ * pointing to the @params elements. I.e. callers must not use
+ * 'virTypedParamsFree' or equivalent on pointer returned via @ret.
+ *
+ * Returns amount of elements in @ret.
*/
-int
+size_t
virTypedParamsFilter(virTypedParameterPtr params,
int nparams,
const char *name,
virTypedParameterPtr **ret)
{
- size_t i, n = 0;
+ size_t i;
+ size_t n = 0;
*ret = g_new0(virTypedParameterPtr, nparams);
@@ -443,7 +447,7 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
const char ***values)
{
size_t i, n;
- int nfiltered;
+ size_t nfiltered;
virTypedParameterPtr *filtered = NULL;
virCheckNonNullArgGoto(values, error);
@@ -451,9 +455,6 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
nfiltered = virTypedParamsFilter(params, nparams, name, &filtered);
- if (nfiltered < 0)
- goto error;
-
if (nfiltered)
*values = g_new0(const char *, nfiltered);
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index 7454ef3ce0..afd923aacb 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -81,7 +81,7 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
int nparams,
const char *name,
const char ***values);
-int
+size_t
virTypedParamsFilter(virTypedParameterPtr params,
int nparams,
const char *name,
--
2.46.0