From: Peter Krempa <[email protected]>

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 <[email protected]>
---
 src/util/virtypedparam.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 92f25cea39..bca7478109 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -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);
-- 
2.54.0

Reply via email to