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


> @@ -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;

xenapiConnectNumOfDefinedDomains under this function uses 'int i' after this
patch.

ACK

Jan

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