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

Re: [libvirt] [PATCH 05/32] Convert 'int i' to 'size_t i' in tools/ files



On Tue, Jul 09, 2013 at 08:01:22PM +0800, Guannan Ren wrote:
> On 07/08/2013 10:21 PM, Daniel P. Berrange wrote:
> >From: "Daniel P. Berrange" <berrange redhat com>
> >
> >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 redhat com>
> >---
> >  tools/virsh-domain-monitor.c | 17 +++++++++--------
> >  tools/virsh-domain.c         | 41 +++++++++++++++++++++++------------------
> >  tools/virsh-host.c           |  8 ++++----
> >  tools/virsh-interface.c      |  6 +++---
> >  tools/virsh-network.c        |  6 +++---
> >  tools/virsh-nodedev.c        |  8 ++++----
> >  tools/virsh-nwfilter.c       |  6 +++---
> >  tools/virsh-pool.c           |  7 ++++---
> >  tools/virsh-secret.c         |  6 +++---
> >  tools/virsh-snapshot.c       | 12 ++++++------
> >  tools/virsh-volume.c         |  6 +++---
> >  tools/virsh.c                | 15 ++++++++-------
> >  12 files changed, 73 insertions(+), 65 deletions(-)
> 
> >diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> >index 5257416..be650c2 100644
> >--- a/tools/virsh-domain.c
> >+++ b/tools/virsh-domain.c
> 
> In cmdUndefine(), there are two variables of int type needing conversion.
> int vol_i
> int tok_i

Squashing in

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 14fa79d..c08b0e9 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2937,8 +2937,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
     char *def = NULL;
     char *source = NULL;
     char *target = NULL;
-    int vol_i;
-    int tok_i;
+    size_t i;
+    size_t j;
     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
     xmlNodePtr *vol_nodes = NULL;
@@ -3046,8 +3046,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
         if (nvolumes > 0)
             vlist = vshCalloc(ctl, nvolumes, sizeof(*vlist));
 
-        for (vol_i = 0; vol_i < nvolumes; vol_i++) {
-            ctxt->node = vol_nodes[vol_i];
+        for (i = 0; i < nvolumes; i++) {
+            ctxt->node = vol_nodes[i];
 
             /* get volume source and target paths */
             if (!(target = virXPathString("string(./target/@dev)", ctxt)))
@@ -3067,12 +3067,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
             /* lookup if volume was selected by user */
             if (volumes) {
                 volume_tok = NULL;
-                for (tok_i = 0; tok_i < nvolume_tokens; tok_i++) {
-                    if (volume_tokens[tok_i] &&
-                        (STREQ(volume_tokens[tok_i], target) ||
-                         STREQ(volume_tokens[tok_i], source))) {
-                        volume_tok = volume_tokens[tok_i];
-                        volume_tokens[tok_i] = NULL;
+                for (j = 0; j < nvolume_tokens; j++) {
+                    if (volume_tokens[j] &&
+                        (STREQ(volume_tokens[j], target) ||
+                         STREQ(volume_tokens[j], source))) {
+                        volume_tok = volume_tokens[j];
+                        volume_tokens[j] = NULL;
                         break;
                     }
                 }
@@ -3095,11 +3095,11 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
 
         /* print volumes specified by user that were not found in domain definition */
         if (volumes) {
-            for (tok_i = 0; tok_i < nvolume_tokens; tok_i++) {
-                if (volume_tokens[tok_i]) {
+            for (j = 0; j < nvolume_tokens; j++) {
+                if (volume_tokens[j]) {
                     vshError(ctl, _("Volume '%s' was not found in domain's "
                                     "definition.\n"),
-                             volume_tokens[tok_i]);
+                             volume_tokens[j]);
                     vol_not_found = true;
                 }
             }
@@ -3162,12 +3162,12 @@ out:
 
     /* try to undefine storage volumes associated with this domain, if it's requested */
     if (nvols) {
-        for (vol_i = 0; vol_i < nvols; vol_i++) {
+        for (i = 0; i < nvols; i++) {
             if (wipe_storage) {
                 vshPrint(ctl, _("Wiping volume '%s'(%s) ... "),
-                         vlist[vol_i].target, vlist[vol_i].source);
+                         vlist[i].target, vlist[i].source);
                 fflush(stdout);
-                if (virStorageVolWipe(vlist[vol_i].vol, 0) < 0) {
+                if (virStorageVolWipe(vlist[i].vol, 0) < 0) {
                     vshError(ctl, _("Failed! Volume not removed."));
                     ret = false;
                     continue;
@@ -3177,23 +3177,23 @@ out:
             }
 
             /* delete the volume */
-            if (virStorageVolDelete(vlist[vol_i].vol, 0) < 0) {
+            if (virStorageVolDelete(vlist[i].vol, 0) < 0) {
                 vshError(ctl, _("Failed to remove storage volume '%s'(%s)"),
-                         vlist[vol_i].target, vlist[vol_i].source);
+                         vlist[i].target, vlist[i].source);
                 ret = false;
             } else {
                 vshPrint(ctl, _("Volume '%s'(%s) removed.\n"),
-                         vlist[vol_i].target, vlist[vol_i].source);
+                         vlist[i].target, vlist[i].source);
             }
         }
     }
 
 cleanup:
-    for (vol_i = 0; vol_i < nvols; vol_i++) {
-        VIR_FREE(vlist[vol_i].source);
-        VIR_FREE(vlist[vol_i].target);
-        if (vlist[vol_i].vol)
-            virStorageVolFree(vlist[vol_i].vol);
+    for (i = 0; i < nvols; i++) {
+        VIR_FREE(vlist[i].source);
+        VIR_FREE(vlist[i].target);
+        if (vlist[i].vol)
+            virStorageVolFree(vlist[i].vol);
     }
     VIR_FREE(vlist);
 


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


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