]> xenbits.xensource.com Git - libvirt.git/commitdiff
virTypedParamsGetStringList: Ensure that returned string list is NULL-terminated
authorPeter Krempa <pkrempa@redhat.com>
Fri, 27 Sep 2024 09:28:22 +0000 (11:28 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Oct 2024 10:57:02 +0000 (12:57 +0200)
This can simplify callers who don't really need to know the number of
elements to check that a particular element is present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/util/virtypedparam.c

index 564cb81acc223a143eb7661aa4b3fc11277b33d0..f25530a735192a2d861e9f22fbf3048bd5a7d98e 100644 (file)
@@ -439,8 +439,8 @@ virTypedParamsFilter(virTypedParameterPtr params,
  * @values: array of returned values
  *
  * Finds all parameters with desired @name within @params and
- * store their values into @values. If none of the @params are strings named
- * @name the returned @values will be NULL.
+ * store their values into a NULL-terminated string list @values. If none of
+ * the @params are strings named @name the returned @values will be NULL.
  *
  * Important: The strings in the returned string list @values are borrowed from
  * @params and thus caller must free only the pointer returned as @values, but
@@ -465,7 +465,7 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
     if (nfiltered == 0)
         return 0;
 
-    *values = g_new0(const char *, nfiltered);
+    *values = g_new0(const char *, nfiltered + 1);
 
     for (i = 0; i < nfiltered; i++) {
         (*values)[i] = filtered[i]->value.s;