[libvirt] [PATCH 05/32] Convert 'int i' to 'size_t i' in tools/ files
Daniel P. Berrange
berrange at redhat.com
Wed Jul 10 11:21:42 UTC 2013
On Tue, Jul 09, 2013 at 12:05:53PM +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>
> > ---
> > 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-secret.c b/tools/virsh-secret.c
> > index fb10119..ac11e53 100644
> > --- a/tools/virsh-secret.c
> > +++ b/tools/virsh-secret.c
> > @@ -367,7 +367,7 @@ typedef struct vshSecretList *vshSecretListPtr;
> > static void
> > vshSecretListFree(vshSecretListPtr list)
> > {
> > - int i;
> > + size_t i;
> >
> > if (list && list->nsecrets) {
> > for (i = 0; i < list->nsecrets; i++) {
> > @@ -384,7 +384,7 @@ vshSecretListCollect(vshControl *ctl,
> > unsigned int flags)
> > {
> > vshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
> > - int i;
> > + size_t i;
> > int ret;
> > virSecretPtr secret;
> > bool success = false;
>
> If we use the fallback method and virConnectNumOfSecrets returns -1,
> the cleanup loop might take too long:
> for (i = 0; i < nsecrets; i++)
>
> > @@ -1095,7 +1095,7 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
> > virDomainSnapshotPtr from,
> > unsigned int orig_flags, bool tree)
> > {
> > - int i;
> > + size_t i;
> > char **names = NULL;
> > int count = -1;
> > bool descendants = false;
>
> Same in this function.
>
> > @@ -1203,7 +1203,7 @@ vshStorageVolListCollect(vshControl *ctl,
> > unsigned int flags)
> > {
> > vshStorageVolListPtr list = vshMalloc(ctl, sizeof(*list));
> > - int i;
> > + size_t i;
> > char **names = NULL;
> > virStorageVolPtr vol = NULL;
> > bool success = false;
>
> This one too.
>
> ACK
Squashing in
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index ac11e53..9d34c1a 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -461,9 +461,11 @@ finished:
success = true;
cleanup:
- for (i = 0; i < nsecrets; i++)
- VIR_FREE(uuids[i]);
- VIR_FREE(uuids);
+ if (nsecrets > 0) {
+ for (i = 0; i < nsecrets; i++)
+ VIR_FREE(uuids[i]);
+ VIR_FREE(uuids);
+ }
if (!success) {
vshSecretListFree(list);
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index a315e28..cfe8ee9 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1408,7 +1408,7 @@ success:
cleanup:
vshSnapshotListFree(snaplist);
- if (names)
+ if (names && count > 0)
for (i = 0; i < count; i++)
VIR_FREE(names[i]);
VIR_FREE(names);
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 3166542..7dab532 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -1273,8 +1273,9 @@ finished:
success = true;
cleanup:
- for (i = 0; i < nvols; i++)
- VIR_FREE(names[i]);
+ if (nvols > 0)
+ for (i = 0; i < nvols; i++)
+ VIR_FREE(names[i]);
VIR_FREE(names);
if (!success) {
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