[PATCH 4/4] hyverv: hypervCreateEmbeddedParam: Rework items counting

Michal Privoznik mprivozn at redhat.com
Mon Oct 19 11:35:08 UTC 2020


It's not necessarily clear, why we need to create the hash table
as big as number of fields we want to store, but nevertheless,
the code can be written a bit better. The @count should be type
of size_t and could be used directly in the loop that counts the
fields.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/hyperv/hyperv_wmi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 489bb03a9b..8bebf02a50 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -317,10 +317,9 @@ virHashTablePtr
 hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr info)
 {
     size_t i;
-    int count = 0;
+    size_t count;
     g_autoptr(virHashTable) table = NULL;
     XmlSerializerInfo *typeinfo = NULL;
-    XmlSerializerInfo *item = NULL;
     hypervWmiClassInfoPtr classInfo = NULL;
 
     /* Get the typeinfo out of the class info list */
@@ -330,15 +329,15 @@ hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr info)
     typeinfo = classInfo->serializerInfo;
 
     /* loop through the items to find out how many fields there are */
-    for (i = 0; typeinfo[i].name != NULL; i++) {}
-    count = i;
+    for (count = 0; typeinfo[count].name != NULL; count++)
+        ;
 
     table = virHashCreate(count, NULL);
     if (table == NULL)
         return NULL;
 
     for (i = 0; typeinfo[i].name != NULL; i++) {
-        item = &typeinfo[i];
+        XmlSerializerInfo *item = &typeinfo[i];
 
         if (virHashAddEntry(table, item->name, NULL) < 0)
             return NULL;
-- 
2.26.2




More information about the libvir-list mailing list