]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyverv: hypervCreateEmbeddedParam: Rework items counting
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Oct 2020 10:08:46 +0000 (12:08 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 20 Oct 2020 10:12:21 +0000 (12:12 +0200)
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@redhat.com>
Reviewed-by: Matt Coleman <matt@datto.com>
src/hyperv/hyperv_wmi.c

index 489bb03a9b3ae04e97c137e4eadb381491f167c5..8bebf02a502d0c18d62182acfe65dc8ec3ade6bd 100644 (file)
@@ -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;