Re: [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]

 



On Tue, Jul 09, 2013 at 12:58:11PM +0200, Ján Tomko wrote:
> On 07/08/2013 04:21 PM, Daniel P. Berrange wrote:
> > 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(-)
> 
> > @@ -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) {
> 
> This function gets called with startCells = -1, which is then assigned to i.
> 
> > @@ -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)
> 
> On error:
>      for (i = 0; i < ret; ++i)
> 

Squashing in

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 08d47ea..39334b7 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2445,7 +2445,8 @@ static int
 xenUnifiedNodeDeviceAssignedDomainId(virNodeDevicePtr dev)
 {
     int numdomains;
-    int ret = -1, i;
+    int ret = -1;
+    size_t i;
     int *ids = NULL;
     char *bdf = NULL;
     char *xref = NULL;
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 333cd9e..39e641e 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2592,7 +2592,8 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn, const unsigned char *uuid)
     xenUnifiedPrivatePtr priv = conn->privateData;
     virDomainDefPtr ret;
     char *name;
-    int maxids = 100, nids, i, id;
+    int maxids = 100, nids, id;
+    size_t i;
 
  retry:
     if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) {
@@ -2840,7 +2841,8 @@ xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn,
                                     int maxCells)
 {
     xen_op_v2_sys op_sys;
-    size_t i, j;
+    size_t i;
+    int cell;
     int ret;
     xenUnifiedPrivatePtr priv = conn->privateData;
 
@@ -2868,22 +2870,22 @@ xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn,
     memset(&op_sys, 0, sizeof(op_sys));
     op_sys.cmd = XEN_V2_OP_GETAVAILHEAP;
 
-    for (i = startCell, j = 0;
-         i < priv->nbNodeCells && j < maxCells; i++, j++) {
+    for (cell = startCell, i = 0;
+         cell < priv->nbNodeCells && i < maxCells; cell++, i++) {
         if (hv_versions.sys_interface >= 5)
-            op_sys.u.availheap5.node = i;
+            op_sys.u.availheap5.node = cell;
         else
-            op_sys.u.availheap.node = i;
+            op_sys.u.availheap.node = cell;
         ret = xenHypervisorDoV2Sys(priv->handle, &op_sys);
         if (ret < 0) {
             return -1;
         }
         if (hv_versions.sys_interface >= 5)
-            freeMems[j] = op_sys.u.availheap5.avail_bytes;
+            freeMems[i] = op_sys.u.availheap5.avail_bytes;
         else
-            freeMems[j] = op_sys.u.availheap.avail_bytes;
+            freeMems[i] = op_sys.u.availheap.avail_bytes;
     }
-    return j;
+    return i;
 }
 
 
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 61dacf2..9d61fca 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2907,8 +2907,6 @@ xenDaemonListDefinedDomains(virConnectPtr conn,
     if (root == NULL)
         goto error;
 
-    ret = 0;
-
     /* coverity[copy_paste_error] */
     for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
          _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) {
@@ -2922,16 +2920,16 @@ xenDaemonListDefinedDomains(virConnectPtr conn,
             break;
     }
 
+    ret = 0;
+
 cleanup:
     sexpr_free(root);
     return ret;
 
 error:
-    for (i = 0; i < ret; ++i)
+    for (i = 0; ret != -1 && i < ret; ++i)
         VIR_FREE(names[i]);
 
-    ret = -1;
-
     goto cleanup;
 }
 
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 3a68286..bca19af 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1218,7 +1218,8 @@ xenapiDomainGetVcpus(virDomainPtr dom,
     xen_vm_set *vms = NULL;
     xen_vm vm = NULL;
     xen_string_string_map *vcpu_params = NULL;
-    int nvcpus = 0, i;
+    int nvcpus = 0;
+    size_t i;
     virDomainInfo domInfo;
     virNodeInfo nodeInfo;
     virVcpuInfoPtr ifptr;
@@ -1595,7 +1596,8 @@ xenapiConnectNumOfDefinedDomains(virConnectPtr conn)
 {
     xen_vm_set *result;
     xen_vm_record *record;
-    int DomNum = 0, i;
+    int DomNum = 0;
+    size_t i;
     xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session;
     xen_vm_get_all(session, &result);
     if (result != NULL) {
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index ed81681..fbbbaa9 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -2184,7 +2184,8 @@ xenFormatSxpr(virConnectPtr conn,
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     const char *tmp;
     char *bufout;
-    int hvm = 0, i, vmlocaltime = -1;
+    int hvm = 0, vmlocaltime = -1;
+    size_t i;
     bool in_image = false;
 
     VIR_DEBUG("Formatting domain sexpr");
@@ -2361,7 +2362,7 @@ xenFormatSxpr(virConnectPtr conn,
             }
             if (def->serials) {
                 if ((def->nserials > 1) || (def->serials[0]->target.port != 0)) {
-                    int maxport = -1;
+                    int maxport = -1, port;
                     size_t j = 0;
 
                     virBufferAddLit(&buf, "(serial (");
@@ -2369,13 +2370,13 @@ xenFormatSxpr(virConnectPtr conn,
                         if (def->serials[i]->target.port > maxport)
                             maxport = def->serials[i]->target.port;
 
-                    for (i = 0; i <= maxport; i++) {
+                    for (port = 0; port <= maxport; port++) {
                         virDomainChrDefPtr chr = NULL;
 
-                        if (i)
+                        if (port)
                             virBufferAddLit(&buf, " ");
                         for (j = 0; j < def->nserials; j++) {
-                            if (def->serials[j]->target.port == i) {
+                            if (def->serials[j]->target.port == port) {
                                 chr = def->serials[j];
                                 break;
                             }
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index d08f3cd..1ffea84 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1485,7 +1485,8 @@ virConfPtr xenFormatXM(virConnectPtr conn,
                                    virDomainDefPtr def,
                                    int xendConfigVersion) {
     virConfPtr conf = NULL;
-    int hvm = 0, i, vmlocaltime = 0;
+    int hvm = 0, vmlocaltime = 0;
+    size_t i;
     char *cpus = NULL;
     const char *lifecycle;
     char uuid[VIR_UUID_STRING_BUFLEN];
@@ -1936,7 +1937,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
                     goto cleanup;
             } else {
                 size_t j = 0;
-                int maxport = -1;
+                int maxport = -1, port;
                 virConfValuePtr serialVal = NULL;
 
                 if (VIR_ALLOC(serialVal) < 0)
@@ -1948,10 +1949,10 @@ virConfPtr xenFormatXM(virConnectPtr conn,
                     if (def->serials[i]->target.port > maxport)
                         maxport = def->serials[i]->target.port;
 
-                for (i = 0; i <= maxport; i++) {
+                for (port = 0; port <= maxport; port++) {
                     virDomainChrDefPtr chr = NULL;
                     for (j = 0; j < def->nserials; j++) {
-                        if (def->serials[j]->target.port == i) {
+                        if (def->serials[j]->target.port == port) {
                             chr = def->serials[j];
                             break;
                         }


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
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]