[libvirt] [PATCH 21/32] Convert 'int i' to 'size_t i' in src/node_device/ files

Daniel P. Berrange berrange at redhat.com
Wed Jul 10 15:53:26 UTC 2013


On Tue, Jul 09, 2013 at 02:35:24PM +0200, Ján Tomko wrote:
> On 07/08/2013 04:21 PM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" <berrange at 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 at redhat.com>
> > ---
> >  src/node_device/node_device_driver.c |  6 +++---
> >  src/node_device/node_device_hal.c    |  9 ++++++---
> >  src/nodeinfo.c                       | 24 ++++++++++++------------
> >  3 files changed, 21 insertions(+), 18 deletions(-)
> > 
> 
> > diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> > index a50f892..d48c7ed 100644
> > --- a/src/nodeinfo.c
> > +++ b/src/nodeinfo.c
> > @@ -1041,7 +1041,7 @@ nodeGetCPUCount(void)
> >       * will be consecutive.
> >       */
> >      char *cpupath = NULL;
> > -    int i = 0;
> > +    size_t i = 0;
> >  
> >      if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present")) {
> >          i = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
> 
> linuxParseCPUmax can return -1.

Squashing in

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 56a0023..67fcc58 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -317,7 +317,8 @@ static int udevGenerateDeviceName(struct udev_device *device,
                                   virNodeDeviceDefPtr def,
                                   const char *s)
 {
-    int ret = 0, i = 0;
+    int ret = 0;
+    size_t i;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
     virBufferAsprintf(&buf, "%s_%s",
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index c0de21d..a2a2f73 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1025,16 +1025,17 @@ nodeGetCPUCount(void)
      * will be consecutive.
      */
     char *cpupath = NULL;
-    size_t i = 0;
+    int ncpu;
 
     if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present")) {
-        i = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
+        ncpu = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
     } else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) {
+        ncpu = 0;
         do {
-            i++;
+            ncpu++;
             VIR_FREE(cpupath);
-            if (virAsprintf(&cpupath, "%s/cpu/cpu%zu",
-                            SYSFS_SYSTEM_PATH, i) < 0)
+            if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
+                            SYSFS_SYSTEM_PATH, ncpu) < 0)
                 return -1;
         } while (virFileExists(cpupath));
     } else {
@@ -1045,7 +1046,7 @@ nodeGetCPUCount(void)
     }
 
     VIR_FREE(cpupath);
-    return i;
+    return ncpu;
 #elif defined(__FreeBSD__)
     return freebsdNodeGetCPUCount();
 #else


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




More information about the libvir-list mailing list