]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virTypedParamsValidateTemplate: Fix counting of templates
authorPeter Krempa <pkrempa@redhat.com>
Sat, 16 May 2026 07:52:30 +0000 (09:52 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 19 May 2026 07:43:06 +0000 (09:43 +0200)
There are 2 bugs in virTypedParamsValidateTemplate's counting of the
passed amount of templates:
 - the condition looked for empty strings rather than non-empty ones
 - the count was 1 more than the amount of templates due to use of
   post-increment directly in the condition

Fixes: 45617351585caa2c5bcc51af48bd32fd750e7afd
Closes: https://gitlab.com/libvirt/libvirt/-/work_items/880
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/util/virtypedparam.c

index 92f25cea3968a008080538e83b0662ee489a7189..bca7478109cf71d67df6d9a59329807a1bcc9697 100644 (file)
@@ -213,8 +213,8 @@ virTypedParamsValidateTemplate(virTypedParameterPtr params,
 
     /* we need to copy the list of templates because
      * 'virTypedParamsValidateInternal' will need to sort it */
-    while (*templates[ntemplates++].name == '\0')
-        ;
+    while (*templates[ntemplates].name != '\0')
+        ntemplates++;
 
     templ_copy = g_new0(virTypedParamValidationTemplate, ntemplates);
     memcpy(templ_copy, templates, sizeof(*templates) * ntemplates);