[PATCH 06/32] Convert 'int i' to 'size_t i' in src/{xen, xenapi, xenxs} files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/xen/block_stats.c      |  4 ++--
 src/xen/xen_driver.c       |  4 ++--
 src/xen/xen_hypervisor.c   | 14 ++++++++------
 src/xen/xen_inotify.c      |  4 ++--
 src/xen/xend_internal.c    | 12 +++++++-----
 src/xen/xm_internal.c      |  5 +++--
 src/xen/xs_internal.c      | 27 +++++++++++++++++----------
 src/xenapi/xenapi_driver.c | 30 ++++++++++++++++++------------
 src/xenapi/xenapi_utils.c  | 14 +++++++-------
 src/xenxs/xen_sxpr.c       | 10 +++++-----
 src/xenxs/xen_xm.c         |  6 +++---
 11 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/src/xen/block_stats.c b/src/xen/block_stats.c
index ebb91ea..74f93d1 100644
--- a/src/xen/block_stats.c
+++ b/src/xen/block_stats.c
@@ -78,7 +78,7 @@ read_stat(const char *path)
 {
     char str[64];
     int64_t r;
-    int i;
+    size_t i;
     FILE *fp;
 
     fp = fopen(path, "r");
@@ -109,7 +109,7 @@ read_bd_stat(int device, int domid, const char *str)
         "/sys/devices/xen-backend/tap-%d-%d/statistics/%s"
     };
 
-    int i;
+    size_t i;
     char *path;
     int64_t r;
 
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index f69feb5..f35c272 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2786,7 +2786,7 @@ xenRegister(void)
 void
 xenUnifiedDomainInfoListFree(xenUnifiedDomainInfoListPtr list)
 {
-    int i;
+    size_t i;
 
     if (list == NULL)
         return;
@@ -2861,7 +2861,7 @@ xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr list,
                            int id, char *name,
                            unsigned char *uuid)
 {
-    int i;
+    size_t i;
     for (i = 0; i < list->count; i++) {
         if (list->doms[i]->id == id &&
             STREQ(list->doms[i]->name, name) &&
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 9d9c3ee..6e1b38f 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -1267,7 +1267,7 @@ xenHypervisorSetSchedulerParameters(virConnectPtr conn,
                                     virTypedParameterPtr params,
                                     int nparams)
 {
-    int i;
+    size_t i;
     unsigned int val;
     xenUnifiedPrivatePtr priv = conn->privateData;
     char buf[256];
@@ -2043,7 +2043,7 @@ xenHypervisorBuildCapabilities(virConnectPtr conn, virArch hostarch,
                                int nr_guest_archs)
 {
     virCapsPtr caps;
-    int i;
+    size_t i;
     int hv_major = hv_versions.hv >> 16;
     int hv_minor = hv_versions.hv & 0xFFFF;
 
@@ -2223,7 +2223,7 @@ static virCapsPtr
 xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn)
 {
     struct guest_arch guest_arches[32];
-    int i = 0;
+    size_t i = 0;
     virCapsPtr caps = NULL;
     int pae, longmode;
     const char *hvm;
@@ -2293,7 +2293,7 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn,
     char line[1024], *str, *token;
     regmatch_t subs[4];
     char *saveptr = NULL;
-    int i;
+    size_t i;
 
     char hvm_type[4] = ""; /* "vmx" or "svm" (or "" if not in CPU). */
     int host_pae = 0;
@@ -2846,7 +2846,8 @@ xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn,
                                     int maxCells)
 {
     xen_op_v2_sys op_sys;
-    int i, j, ret;
+    size_t i, j;
+    int ret;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
     if (priv->nbNodeCells < 0) {
@@ -2976,7 +2977,8 @@ xenHypervisorGetVcpus(virConnectPtr conn,
     int ret;
     xenUnifiedPrivatePtr priv = conn->privateData;
     virVcpuInfoPtr ipt;
-    int nbinfo, i;
+    int nbinfo;
+    size_t i;
 
     if (sizeof(cpumap_t) & 7) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c
index 8266576..5d0b6d2 100644
--- a/src/xen/xen_inotify.c
+++ b/src/xen/xen_inotify.c
@@ -72,7 +72,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn,
                                char **name,
                                unsigned char *uuid)
 {
-    int i;
+    size_t i;
     virDomainDefPtr def;
     const char *uuid_str;
     unsigned char rawuuid[VIR_UUID_BUFLEN];
@@ -159,7 +159,7 @@ xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn, const char *fname)
     xenUnifiedPrivatePtr priv = conn->privateData;
     const char *uuidstr = fname + strlen(XEND_DOMAINS_DIR) + 1;
     unsigned char uuid[VIR_UUID_BUFLEN];
-    int i;
+    size_t i;
 
     if (virUUIDParse(uuidstr, uuid) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 3c05dff..89f6f4d 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -748,7 +748,7 @@ xenDaemonListDomainsOld(virConnectPtr xend)
     struct sexpr *root = NULL;
     char **ret = NULL;
     int count = 0;
-    int i;
+    size_t i;
     struct sexpr *_for_i, *node;
 
     root = sexpr_get(xend, "/xend/domain");
@@ -1855,7 +1855,8 @@ xenDaemonDomainPinVcpu(virConnectPtr conn,
                        int maplen)
 {
     char buf[VIR_UUID_BUFLEN], mapstr[sizeof(cpumap_t) * 64];
-    int i, j, ret;
+    size_t i, j;
+    int ret;
     xenUnifiedPrivatePtr priv = conn->privateData;
     virDomainDefPtr def = NULL;
 
@@ -1874,7 +1875,7 @@ xenDaemonDomainPinVcpu(virConnectPtr conn,
     /* from bit map, build character string of mapped CPU numbers */
     for (i = 0; i < maplen; i++) for (j = 0; j < 8; j++)
      if (cpumap[i] & (1 << j)) {
-        snprintf(buf, sizeof(buf), "%d,", (8 * i) + j);
+        snprintf(buf, sizeof(buf), "%zu,", (8 * i) + j);
         strcat(mapstr, buf);
     }
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
@@ -2911,7 +2912,8 @@ xenDaemonListDefinedDomains(virConnectPtr conn,
                             int maxnames)
 {
     struct sexpr *root = NULL;
-    int i, ret = -1;
+    size_t i;
+    int ret = -1;
     struct sexpr *_for_i, *node;
 
     if (maxnames == 0)
@@ -3133,7 +3135,7 @@ xenDaemonSetSchedulerParameters(virConnectPtr conn,
     xenUnifiedPrivatePtr priv = conn->privateData;
     struct sexpr *root;
     char *sched_type = NULL;
-    int i;
+    size_t i;
     int sched_nparam = 0;
     int ret = -1;
 
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 7c05911..b4fd916 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1150,7 +1150,8 @@ xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
 {
     xenUnifiedPrivatePtr priv = conn->privateData;
     struct xenXMListIteratorContext ctx;
-    int i, ret = -1;
+    size_t i;
+    int ret = -1;
 
     xenUnifiedLock(priv);
 
@@ -1321,7 +1322,7 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn,
     virDomainDeviceDefPtr dev = NULL;
     virDomainDefPtr def;
     int ret = -1;
-    int i;
+    size_t i;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index cc55fde..e79585d 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -227,7 +227,8 @@ xenStoreNumOfDomains(virConnectPtr conn)
 {
     unsigned int num;
     char **idlist = NULL, *endptr;
-    int i, ret = -1, realnum = 0;
+    size_t i;
+    int ret = -1, realnum = 0;
     long id;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
@@ -268,7 +269,8 @@ xenStoreDoListDomains(virConnectPtr conn,
                       int maxids)
 {
     char **idlist = NULL, *endptr;
-    unsigned int num, i;
+    unsigned int num;
+    size_t i;
     int ret = -1;
     long id;
 
@@ -408,7 +410,8 @@ char *
 xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac)
 {
     char dir[80], path[128], **list = NULL, *val = NULL;
-    unsigned int len, i, num;
+    unsigned int len, num;
+    size_t i;
     char *ret = NULL;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
@@ -457,7 +460,8 @@ char *
 xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
 {
     char dir[80], path[128], **list = NULL, *val = NULL;
-    unsigned int devlen, len, i, num;
+    unsigned int devlen, len, num;
+    size_t i;
     char *ret = NULL;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
@@ -529,7 +533,8 @@ char *
 xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
 {
     char dir[80], path[128], **list = NULL, *val = NULL;
-    unsigned int len, i, num;
+    unsigned int len, num;
+    size_t i;
     char *ret = NULL;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
@@ -614,7 +619,7 @@ xenStoreDomainGetUUID(virConnectPtr conn, int id, unsigned char *uuid)
 static void
 xenStoreWatchListFree(xenStoreWatchListPtr list)
 {
-    int i;
+    size_t i;
     for (i=0; i<list->count; i++) {
         VIR_FREE(list->watches[i]->path);
         VIR_FREE(list->watches[i]->token);
@@ -695,7 +700,7 @@ xenStoreAddWatch(virConnectPtr conn,
 int
 xenStoreRemoveWatch(virConnectPtr conn, const char *path, const char *token)
 {
-    int i;
+    size_t i;
     xenStoreWatchListPtr list;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
@@ -744,7 +749,7 @@ xenStoreFindWatch(xenStoreWatchListPtr list,
                   const char *path,
                   const char *token)
 {
-    int i;
+    size_t i;
     for (i = 0; i < list->count; i++)
         if (STREQ(path, list->watches[i]->path) &&
             STREQ(token, list->watches[i]->token))
@@ -805,7 +810,8 @@ xenStoreDomainIntroduced(virConnectPtr conn,
                          const char *token ATTRIBUTE_UNUSED,
                          void *opaque)
 {
-    int i, j, found, missing = 0, retries = 20;
+    size_t i, j;
+    int found, missing = 0, retries = 20;
     int new_domain_cnt;
     int *new_domids;
     int nread;
@@ -887,7 +893,8 @@ xenStoreDomainReleased(virConnectPtr conn,
                        const char *token ATTRIBUTE_UNUSED,
                        void *opaque)
 {
-    int i, j, found, removed, retries = 20;
+    size_t i, j;
+    int found, removed, retries = 20;
     int new_domain_cnt;
     int *new_domids;
     int nread;
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index cc8da49..7913ade 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -301,7 +301,8 @@ xenapiConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
     xen_host host;
     xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session;
     xen_string_string_map *result = NULL;
-    int i, ret = -1;
+    size_t i;
+    int ret = -1;
     char *version = NULL;
     if (!(xen_session_get_this_host(session, &host, session))) {
         xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);
@@ -465,7 +466,7 @@ xenapiConnectListDomains(virConnectPtr conn, int *ids, int maxids)
     xen_host host;
     xen_vm_set *result = NULL;
     int64_t t0;
-    int i;
+    size_t i;
     xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session;
     if (xen_session_get_this_host(session, &host, session)) {
         xen_host_get_resident_vms(session, &result, host);
@@ -579,7 +580,7 @@ xenapiDomainCreateXML(virConnectPtr conn,
 static virDomainPtr
 xenapiDomainLookupByID(virConnectPtr conn, int id)
 {
-    int i;
+    size_t i;
     int64_t domID;
     char *uuid;
     xen_host host;
@@ -1390,7 +1391,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         }
         xen_vm_get_hvm_boot_params(session, &result, vm);
         if (result != NULL) {
-            int i;
+            size_t i;
             for (i = 0; i < result->size; i++) {
                 if (STREQ(result->contents[i].key, "order")) {
                     int cnt = 0;
@@ -1475,7 +1476,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     }
     xen_vm_get_platform(session, &result, vm);
     if (result != NULL) {
-        int i;
+        size_t i;
         for (i = 0; i < result->size; i++) {
             if (STREQ(result->contents[i].val, "true")) {
                 if (STREQ(result->contents[i].key, "acpi"))
@@ -1494,7 +1495,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     }
     xen_vm_get_vifs(session, &vif_set, vm);
     if (vif_set) {
-        int i;
+        size_t i;
         xen_vif vif;
         xen_vif_record *vif_rec = NULL;
         xen_network network;
@@ -1553,13 +1554,15 @@ static int
 xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names,
                                 int maxnames)
 {
-    int i,j=0,doms;
+    size_t i, j;
+    int doms;
     xen_vm_set *result;
     xen_vm_record *record;
     xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session;
     xen_vm_get_all(session, &result);
+    memset(names, 0, sizeof(names[0])*maxnames);
     if (result != NULL) {
-        for (i = 0; i < result->size && j < maxnames; i++) {
+        for (i = 0, j = 0; i < result->size && j < maxnames; i++) {
             xen_vm_get_record(session, &record, result->contents[i]);
             if (record != NULL) {
                 if (record->is_a_template == 0) {
@@ -1567,7 +1570,8 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names,
                     if (VIR_STRDUP(usenames, record->name_label) < 0) {
                         xen_vm_record_free(record);
                         xen_vm_set_free(result);
-                        while (--j >= 0) VIR_FREE(names[j]);
+                        for (i = 0; i < maxnames; i++)
+                            VIR_FREE(names[j]);
                         return -1;
                     }
                     names[j++] = usenames;
@@ -1577,8 +1581,9 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names,
                 xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR,
                                           _("Couldn't get VM record"));
                 xen_vm_set_free(result);
-                while (--j >= 0) VIR_FREE(names[j]);
-                   return -1;
+                for (i = 0; i < maxnames; i++)
+                    VIR_FREE(names[j]);
+                return -1;
             }
         }
         doms = j;
@@ -1772,7 +1777,8 @@ xenapiDomainUndefine(virDomainPtr dom)
 static int
 xenapiDomainGetAutostart(virDomainPtr dom, int *autostart)
 {
-    int i,flag=0;
+    size_t i;
+    int flag = 0;
     xen_vm_set *vms;
     xen_vm vm;
     xen_string_string_map *result;
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 46e1aea..137f29d 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -41,7 +41,7 @@
 void
 xenSessionFree(xen_session *session)
 {
-    int i;
+    size_t i;
     if (session->error_description != NULL) {
         for (i = 0; i < session->error_description_count; i++)
             VIR_FREE(session->error_description[i]);
@@ -95,7 +95,7 @@ int
 xenapiUtil_ParseQuery(virConnectPtr conn, virURIPtr uri, int *noVerify)
 {
     int result = 0;
-    int i;
+    size_t i;
 
     for (i = 0; i < uri->paramsCount; i++) {
         virURIParamPtr queryParam = &uri->params[i];
@@ -161,7 +161,7 @@ createXenAPIBootOrderString(int nboot, int *bootDevs)
 {
     virBuffer ret = VIR_BUFFER_INITIALIZER;
     char *val = NULL;
-    int i;
+    size_t i;
     for (i = 0; i < nboot; i++) {
         if (bootDevs[i] == VIR_DOMAIN_BOOT_FLOPPY)
             val = (char *)"a";
@@ -253,7 +253,7 @@ getStorageVolumeType(char *type)
 char *
 returnErrorFromSession(xen_session *session)
 {
-    int i;
+    size_t i;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     for (i = 0; i < session->error_description_count; i++) {
         if (!i)
@@ -273,11 +273,11 @@ mapDomainPinVcpu(unsigned char *cpumap, int maplen)
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     size_t len;
     char *ret = NULL;
-    int i, j;
+    size_t i, j;
     for (i = 0; i < maplen; i++) {
         for (j = 0; j < 8; j++) {
             if (cpumap[i] & (1 << j)) {
-                virBufferAsprintf(&buf, "%d,", (8*i)+j);
+                virBufferAsprintf(&buf, "%zu,", (8*i)+j);
             }
         }
     }
@@ -452,7 +452,7 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
     char uuidStr[VIR_UUID_STRING_BUFLEN];
     xen_string_string_map *strings = NULL;
     int device_number = 0;
-    int i;
+    size_t i;
 
     *record = xen_vm_record_alloc();
     if (VIR_STRDUP((*record)->name_label, def->name) < 0)
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 394b814..a275012 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -634,7 +634,7 @@ xenParseSxprSound(virDomainDefPtr def,
                   const char *str)
 {
     if (STREQ(str, "all")) {
-        int i;
+        size_t i;
 
         /*
          * Special compatibility code for Xen with a bogus
@@ -1356,7 +1356,7 @@ xenParseSxpr(const struct sexpr *root,
     /* Floppy disk config */
     if (hvm) {
         const char *const fds[] = { "fda", "fdb" };
-        int i;
+        size_t i;
         for (i = 0; i < ARRAY_CARDINALITY(fds); i++) {
             tmp = sexpr_fmt_node(root, "domain/image/hvm/%s", fds[i]);
             if ((tmp != NULL) && (tmp[0] != 0)) {
@@ -2069,7 +2069,7 @@ xenFormatSxprAllPCI(virDomainDefPtr def,
                     virBufferPtr buf)
 {
     int hasPCI = 0;
-    int i;
+    size_t i;
 
     for (i = 0; i < def->nhostdevs; i++)
         if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
@@ -2126,7 +2126,7 @@ xenFormatSxprSound(virDomainDefPtr def,
                    virBufferPtr buf)
 {
     const char *str;
-    int i;
+    size_t i;
 
     for (i = 0; i < def->nsounds; i++) {
         if (!(str = virDomainSoundModelTypeToString(def->sounds[i]->model))) {
@@ -2382,7 +2382,7 @@ xenFormatSxpr(virConnectPtr conn,
             if (def->serials) {
                 if ((def->nserials > 1) || (def->serials[0]->target.port != 0)) {
                     int maxport = -1;
-                    int j = 0;
+                    size_t j = 0;
 
                     virBufferAddLit(&buf, "(serial (");
                     for (i = 0; i < def->nserials; i++)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 9905f9d..036e450 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -258,7 +258,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
     virDomainNetDefPtr net = NULL;
     virDomainGraphicsDefPtr graphics = NULL;
     virDomainHostdevDefPtr hostdev = NULL;
-    int i;
+    size_t i;
     const char *defaultMachine;
     int vmlocaltime = 0;
     unsigned long count;
@@ -1435,7 +1435,7 @@ xenFormatXMPCI(virConfPtr conf,
 
     virConfValuePtr pciVal = NULL;
     int hasPCI = 0;
-    int i;
+    size_t i;
 
     for (i = 0; i < def->nhostdevs; i++)
         if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
@@ -1958,7 +1958,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
                 if (ret < 0)
                     goto no_memory;
             } else {
-                int j = 0;
+                size_t j = 0;
                 int maxport = -1;
                 virConfValuePtr serialVal = NULL;
 
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]