From d8960bff712800fff388b455f581506efa25cf76 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 19 Oct 2020 12:08:46 +0200 Subject: [PATCH] hyverv: hypervCreateEmbeddedParam: Rework items counting 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 Reviewed-by: Matt Coleman --- 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;