[PATCH v2 03/11] virDomainIothreadMappingDefParse: Fix usage of virXMLNodeGetSubelementList

Peter Krempa posted 11 patches 1 week, 1 day ago
[PATCH v2 03/11] virDomainIothreadMappingDefParse: Fix usage of virXMLNodeGetSubelementList
Posted by Peter Krempa 1 week, 1 day ago
virXMLNodeGetSubelementList always returns a non-NULL pointers thus we
should check the lenght instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5630a469be..2b9955a1a0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7950,19 +7950,21 @@ virDomainIothreadMappingDefParse(xmlNodePtr driverNode,
     if (!(iothreadsNode = virXMLNodeGetSubelement(driverNode, "iothreads")))
         return 0;

-    if (!(iothreadNodes = virXMLNodeGetSubelementList(iothreadsNode, "iothread")))
+    iothreadNodes = virXMLNodeGetSubelementList(iothreadsNode, "iothread");
+
+    if (iothreadNodes->len == 0)
         return 0;

     for (i = 0; i < iothreadNodes->len; i++) {
         xmlNodePtr iothNode = g_ptr_array_index(iothreadNodes, i);
         g_autoptr(virDomainIothreadMappingDef) iothdef = g_new0(virDomainIothreadMappingDef, 1);
-        g_autoptr(GPtrArray) queueNodes = NULL;
+        g_autoptr(GPtrArray) queueNodes = virXMLNodeGetSubelementList(iothNode, "queue");

         if (virXMLPropUInt(iothNode, "id", 10, VIR_XML_PROP_REQUIRED,
                            &iothdef->id) < 0)
             return -1;

-        if ((queueNodes = virXMLNodeGetSubelementList(iothNode, "queue"))) {
+        if (queueNodes->len > 0) {
             size_t q;

             iothdef->queues = g_new0(unsigned int, queueNodes->len);
-- 
2.48.1
Re: [PATCH v2 03/11] virDomainIothreadMappingDefParse: Fix usage of virXMLNodeGetSubelementList
Posted by Ján Tomko 21 hours ago
On a Monday in 2025, Peter Krempa wrote:
>virXMLNodeGetSubelementList always returns a non-NULL pointers thus we
>should check the lenght instead.

*length

>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/conf/domain_conf.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano