From d8e29bde57334d608db8adbe3cc01035995f5563 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 15 Mar 2024 17:46:17 +0000 Subject: [PATCH] Silence conversion warnings in libsrc4 --- libsrc4/nc4attr.c | 2 +- libsrc4/nc4cache.c | 4 +-- libsrc4/nc4dim.c | 6 ++--- libsrc4/nc4grp.c | 13 ++++------ libsrc4/nc4internal.c | 57 ++++++++++++++++++++----------------------- libsrc4/nc4type.c | 5 ++-- libsrc4/nc4var.c | 14 +++++------ libsrc4/ncindex.c | 3 +-- 8 files changed, 46 insertions(+), 58 deletions(-) diff --git a/libsrc4/nc4attr.c b/libsrc4/nc4attr.c index 2cb5e59462..47c4fb7b86 100644 --- a/libsrc4/nc4attr.c +++ b/libsrc4/nc4attr.c @@ -195,7 +195,7 @@ nc4_get_att(int ncid, int varid, const char *name, nc_type *xtype, /* Check varid */ if (varid != NC_GLOBAL) { - if (!(var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid))) + if (!(var = (NC_VAR_INFO_T*)ncindexith(grp->vars,(size_t)varid))) return NC_ENOTVAR; assert(var->hdr.id == varid); } diff --git a/libsrc4/nc4cache.c b/libsrc4/nc4cache.c index f41b327a3f..393f4a419b 100644 --- a/libsrc4/nc4cache.c +++ b/libsrc4/nc4cache.c @@ -127,8 +127,8 @@ nc_set_chunk_cache_ints(int size, int nelems, int preemption) NCglobalstate* gs = NC_getglobalstate(); if (size <= 0 || nelems <= 0 || preemption < 0 || preemption > 100) return NC_EINVAL; - gs->chunkcache.size = size; - gs->chunkcache.nelems = nelems; + gs->chunkcache.size = (size_t)size; + gs->chunkcache.nelems = (size_t)nelems; gs->chunkcache.preemption = (float)preemption / 100; return NC_NOERR; } diff --git a/libsrc4/nc4dim.c b/libsrc4/nc4dim.c index 2082712d32..c9f4354ed0 100644 --- a/libsrc4/nc4dim.c +++ b/libsrc4/nc4dim.c @@ -37,7 +37,6 @@ NC4_inq_unlimdim(int ncid, int *unlimdimidp) NC_DIM_INFO_T *dim; int found = 0; int retval; - int i; LOG((2, "%s: called", __func__)); @@ -52,7 +51,7 @@ NC4_inq_unlimdim(int ncid, int *unlimdimidp) *unlimdimidp = -1; for (g = grp; g && !found; g = g->parent) { - for(i=0;idim);i++) + for(size_t i=0;idim);i++) { dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i); if(dim == NULL) continue; @@ -178,7 +177,6 @@ NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp) NC_FILE_INFO_T *h5; int num_unlim = 0; int retval; - int i; LOG((2, "%s: ncid 0x%x", __func__, ncid)); @@ -190,7 +188,7 @@ NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp) /* Get our dim info. */ assert(h5); { - for(i=0;idim);i++) + for(size_t i=0;idim);i++) { dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i); if(dim == NULL) continue; diff --git a/libsrc4/nc4grp.c b/libsrc4/nc4grp.c index 7e97ad9fda..ee6dc1e7ab 100644 --- a/libsrc4/nc4grp.c +++ b/libsrc4/nc4grp.c @@ -87,7 +87,6 @@ NC4_inq_grps(int ncid, int *numgrps, int *ncids) NC_FILE_INFO_T *h5; int num = 0; int retval; - int i; LOG((2, "nc_inq_grps: ncid 0x%x", ncid)); @@ -97,7 +96,7 @@ NC4_inq_grps(int ncid, int *numgrps, int *ncids) assert(h5); /* Count the number of groups in this group. */ - for(i=0;ichildren);i++) + for(size_t i=0;ichildren);i++) { g = (NC_GRP_INFO_T*)ncindexith(grp->children,i); if(g == NULL) continue; @@ -349,7 +348,6 @@ NC4_inq_varids(int ncid, int *nvars, int *varids) NC_VAR_INFO_T *var; int num_vars = 0; int retval; - int i; LOG((2, "nc_inq_varids: ncid 0x%x", ncid)); @@ -360,7 +358,7 @@ NC4_inq_varids(int ncid, int *nvars, int *varids) /* This is a netCDF-4 group. Round up them doggies and count * 'em. The list is in correct (i.e. creation) order. */ - for (i=0; i < ncindexsize(grp->vars); i++) + for (size_t i=0; i < ncindexsize(grp->vars); i++) { var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i); if (!var) continue; @@ -438,10 +436,9 @@ NC4_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents) if (dimids) { int n = 0; - int i; /* Get dimension ids from this group. */ - for(i=0;idim);i++) { + for(size_t i=0;idim);i++) { dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i); if(dim == NULL) continue; dimids[n++] = dim->hdr.id; @@ -450,13 +447,13 @@ NC4_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents) /* Get dimension ids from parent groups. */ if (include_parents) for (g = grp->parent; g; g = g->parent) { - for(i=0;idim);i++) { + for(size_t i=0;idim);i++) { dim = (NC_DIM_INFO_T*)ncindexith(g->dim,i); if(dim == NULL) continue; dimids[n++] = dim->hdr.id; } } - qsort(dimids, num, sizeof(int), int_cmp); + qsort(dimids, (size_t)num, sizeof(int), int_cmp); } /* If the user wants the number of dims, give it. */ diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index 31e0302871..5508e8612d 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -472,7 +472,7 @@ nc4_find_grp_h5_var(int ncid, int varid, NC_FILE_INFO_T **h5, NC_GRP_INFO_T **gr assert(my_grp && my_h5); /* Find the var. */ - if (!(my_var = (NC_VAR_INFO_T *)ncindexith(my_grp->vars, varid))) + if (!(my_var = (NC_VAR_INFO_T *)ncindexith(my_grp->vars, (size_t)varid))) return NC_ENOTVAR; assert(my_var && my_var->hdr.id == varid); @@ -552,7 +552,6 @@ nc4_rec_find_named_type(NC_GRP_INFO_T *start_grp, char *name) { NC_GRP_INFO_T *g; NC_TYPE_INFO_T *type, *res; - int i; assert(start_grp); @@ -562,7 +561,7 @@ nc4_rec_find_named_type(NC_GRP_INFO_T *start_grp, char *name) return type; /* Search subgroups. */ - for(i=0;ichildren);i++) { + for(size_t i=0;ichildren);i++) { g = (NC_GRP_INFO_T*)ncindexith(start_grp->children,i); if(g == NULL) continue; if ((res = nc4_rec_find_named_type(g, name))) @@ -639,7 +638,7 @@ nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum, } else { - var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid); + var = (NC_VAR_INFO_T*)ncindexith(grp->vars,(size_t)varid); if (!var) return NC_ENOTVAR; attlist = var->att; @@ -651,7 +650,7 @@ nc4_find_grp_att(NC_GRP_INFO_T *grp, int varid, const char *name, int attnum, if (name) my_att = (NC_ATT_INFO_T *)ncindexlookup(attlist, name); else - my_att = (NC_ATT_INFO_T *)ncindexith(attlist, attnum); + my_att = (NC_ATT_INFO_T *)ncindexith(attlist, (size_t)attnum); if (!my_att) return NC_ENOTATT; @@ -715,7 +714,7 @@ obj_track(NC_FILE_INFO_T* file, NC_OBJ* obj) assert(NC_FALSE); } /* Insert at the appropriate point in the list */ - nclistset(list,obj->id,obj); + nclistset(list,(size_t)obj->id,obj); } /** @@ -748,7 +747,7 @@ nc4_var_list_add2(NC_GRP_INFO_T *grp, const char *name, NC_VAR_INFO_T **var) new_var->chunkcache.preemption = gs->chunkcache.preemption; /* Now fill in the values in the var info structure. */ - new_var->hdr.id = ncindexsize(grp->vars); + new_var->hdr.id = (int)ncindexsize(grp->vars); if (!(new_var->hdr.name = strdup(name))) { if(new_var) free(new_var); @@ -784,7 +783,7 @@ nc4_var_set_ndims(NC_VAR_INFO_T *var, int ndims) assert(var); /* Remember the number of dimensions. */ - var->ndims = ndims; + var->ndims = (size_t)ndims; /* Allocate space for dimension information. */ if (ndims) @@ -912,7 +911,7 @@ nc4_att_list_add(NCindex *list, const char *name, NC_ATT_INFO_T **att) new_att->hdr.sort = NCATT; /* Fill in the information we know. */ - new_att->hdr.id = ncindexsize(list); + new_att->hdr.id = (int)ncindexsize(list); if (!(new_att->hdr.name = strdup(name))) { if(new_att) free(new_att); @@ -1171,7 +1170,7 @@ nc4_field_list_add(NC_TYPE_INFO_T *parent, const char *name, } /* Add object to lists */ - field->hdr.id = nclistlength(parent->u.c.field); + field->hdr.id = (int)nclistlength(parent->u.c.field); nclistpush(parent->u.c.field,field); return NC_NOERR; @@ -1363,14 +1362,13 @@ nc4_att_free(NC_ATT_INFO_T *att) static int var_free(NC_VAR_INFO_T *var) { - int i; int retval; assert(var); LOG((4, "%s: deleting var %s", __func__, var->hdr.name)); /* First delete all the attributes attached to this var. */ - for (i = 0; i < ncindexsize(var->att); i++) + for (size_t i = 0; i < ncindexsize(var->att); i++) if ((retval = nc4_att_free((NC_ATT_INFO_T *)ncindexith(var->att, i)))) return retval; ncindexfree(var->att); @@ -1429,7 +1427,7 @@ nc4_var_list_del(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var) /* Remove from lists */ i = ncindexfind(grp->vars, (NC_OBJ *)var); if (i >= 0) - ncindexidel(grp->vars, i); + ncindexidel(grp->vars, (size_t)i); return var_free(var); } @@ -1472,7 +1470,7 @@ nc4_dim_list_del(NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim) { int pos = ncindexfind(grp->dim, (NC_OBJ *)dim); if(pos >= 0) - ncindexidel(grp->dim, pos); + ncindexidel(grp->dim, (size_t)pos); } return dim_free(dim); @@ -1490,7 +1488,6 @@ nc4_dim_list_del(NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim) int nc4_rec_grp_del(NC_GRP_INFO_T *grp) { - int i; int retval; assert(grp); @@ -1498,34 +1495,34 @@ nc4_rec_grp_del(NC_GRP_INFO_T *grp) /* Recursively call this function for each child, if any, stopping * if there is an error. */ - for (i = 0; i < ncindexsize(grp->children); i++) + for (size_t i = 0; i < ncindexsize(grp->children); i++) if ((retval = nc4_rec_grp_del((NC_GRP_INFO_T *)ncindexith(grp->children, i)))) return retval; ncindexfree(grp->children); /* Free attributes */ - for (i = 0; i < ncindexsize(grp->att); i++) + for (size_t i = 0; i < ncindexsize(grp->att); i++) if ((retval = nc4_att_free((NC_ATT_INFO_T *)ncindexith(grp->att, i)))) return retval; ncindexfree(grp->att); /* Delete all vars. */ - for (i = 0; i < ncindexsize(grp->vars); i++) { - NC_VAR_INFO_T* v = (NC_VAR_INFO_T *)ncindexith(grp->vars, i); + for (size_t i = 0; i < ncindexsize(grp->vars); i++) { + NC_VAR_INFO_T* v = (NC_VAR_INFO_T *)ncindexith(grp->vars, i); if ((retval = var_free(v))) return retval; } ncindexfree(grp->vars); /* Delete all dims, and free the list of dims. */ - for (i = 0; i < ncindexsize(grp->dim); i++) + for (size_t i = 0; i < ncindexsize(grp->dim); i++) if ((retval = dim_free((NC_DIM_INFO_T *)ncindexith(grp->dim, i)))) return retval; ncindexfree(grp->dim); /* Delete all types. */ - for (i = 0; i < ncindexsize(grp->type); i++) + for (size_t i = 0; i < ncindexsize(grp->type); i++) if ((retval = nc4_type_free((NC_TYPE_INFO_T *)ncindexith(grp->type, i)))) return retval; ncindexfree(grp->type); @@ -1551,7 +1548,6 @@ nc4_rec_grp_del(NC_GRP_INFO_T *grp) int nc4_rec_grp_del_att_data(NC_GRP_INFO_T *grp) { - int i; int retval; assert(grp); @@ -1559,25 +1555,24 @@ nc4_rec_grp_del_att_data(NC_GRP_INFO_T *grp) /* Recursively call this function for each child, if any, stopping * if there is an error. */ - for (i = 0; i < ncindexsize(grp->children); i++) + for (size_t i = 0; i < ncindexsize(grp->children); i++) if ((retval = nc4_rec_grp_del_att_data((NC_GRP_INFO_T *)ncindexith(grp->children, i)))) return retval; /* Free attribute data in this group */ - for (i = 0; i < ncindexsize(grp->att); i++) { - NC_ATT_INFO_T * att = (NC_ATT_INFO_T*)ncindexith(grp->att, i); - if((retval = NC_reclaim_data_all(grp->nc4_info->controller,att->nc_typeid,att->data,att->len))) - return retval; + for (size_t i = 0; i < ncindexsize(grp->att); i++) { + NC_ATT_INFO_T * att = (NC_ATT_INFO_T*)ncindexith(grp->att, i); + if((retval = NC_reclaim_data_all(grp->nc4_info->controller,att->nc_typeid,att->data,att->len))) + return retval; att->data = NULL; att->len = 0; att->dirty = 0; } /* Delete att data from all contained vars in this group */ - for (i = 0; i < ncindexsize(grp->vars); i++) { - int j; + for (size_t i = 0; i < ncindexsize(grp->vars); i++) { NC_VAR_INFO_T* v = (NC_VAR_INFO_T *)ncindexith(grp->vars, i); - for(j=0;jatt);j++) { + for(size_t j=0;jatt);j++) { NC_ATT_INFO_T* att = (NC_ATT_INFO_T*)ncindexith(v->att, j); if((retval = NC_reclaim_data_all(grp->nc4_info->controller,att->nc_typeid,att->data,att->len))) return retval; @@ -1604,7 +1599,7 @@ int nc4_att_list_del(NCindex *list, NC_ATT_INFO_T *att) { assert(att && list); - ncindexidel(list, ((NC_OBJ *)att)->id); + ncindexidel(list, (size_t)((NC_OBJ *)att)->id); return nc4_att_free(att); } diff --git a/libsrc4/nc4type.c b/libsrc4/nc4type.c index b0361a55a5..e3af9b1b07 100644 --- a/libsrc4/nc4type.c +++ b/libsrc4/nc4type.c @@ -38,7 +38,7 @@ const char* nc4_atomic_name[NUM_ATOMIC_TYPES] = {"none", "byte", "char", "double", "ubyte", "ushort", "uint", "int64", "uint64", "string"}; -static const int nc4_atomic_size[NUM_ATOMIC_TYPES] = {0, NC_BYTE_LEN, NC_CHAR_LEN, NC_SHORT_LEN, +static const size_t nc4_atomic_size[NUM_ATOMIC_TYPES] = {0, NC_BYTE_LEN, NC_CHAR_LEN, NC_SHORT_LEN, NC_INT_LEN, NC_FLOAT_LEN, NC_DOUBLE_LEN, NC_BYTE_LEN, NC_SHORT_LEN, NC_INT_LEN, NC_INT64_LEN, NC_INT64_LEN, NC_STRING_LEN}; @@ -74,8 +74,7 @@ NC4_inq_typeids(int ncid, int *ntypes, int *typeids) /* Count types. */ if (grp->type) { - int i; - for(i=0;itype);i++) + for(size_t i=0;itype);i++) { if((type = (NC_TYPE_INFO_T*)ncindexith(grp->type,i)) == NULL) continue; if (typeids) diff --git a/libsrc4/nc4var.c b/libsrc4/nc4var.c index 049dbf1196..69efe86fbd 100644 --- a/libsrc4/nc4var.c +++ b/libsrc4/nc4var.c @@ -84,7 +84,7 @@ NC4_get_var_chunk_cache(int ncid, int varid, size_t *sizep, assert(nc && grp && h5); /* Find the var. */ - var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid); + var = (NC_VAR_INFO_T*)ncindexith(grp->vars,(size_t)varid); if(!var) return NC_ENOTVAR; assert(var && var->hdr.id == varid); @@ -129,7 +129,7 @@ nc_get_var_chunk_cache_ints(int ncid, int varid, int *sizep, return ret; if (sizep) - *sizep = real_size / MEGABYTE; + *sizep = (int)(real_size / MEGABYTE); if (nelemsp) *nelemsp = (int)real_nelems; if(preemptionp) @@ -204,7 +204,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, } /* Find the var. */ - if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid))) + if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, (size_t)varid))) return NC_ENOTVAR; assert(var && var->hdr.id == varid); @@ -214,7 +214,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, if (xtypep) *xtypep = var->type_info->hdr.id; if (ndimsp) - *ndimsp = var->ndims; + *ndimsp = (int)var->ndims; if (dimidsp) for (d = 0; d < var->ndims; d++) dimidsp[d] = var->dimids[d]; @@ -575,7 +575,7 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type, }else if (quantize_mode == NC_QUANTIZE_BITROUND){ /* BitRound interprets nsd as number of significant binary digits (bits) */ - prc_bnr_xpl_rqr = nsd; + prc_bnr_xpl_rqr = (unsigned short)nsd; } @@ -1457,7 +1457,7 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type, /* 20211003 Continuous determination of dgt_nbr improves CR by ~10% */ dgt_nbr = (int)floor(xpn_bs2 * dgt_per_bit + mnt_log10_fabs) + 1; /* DGG19 p. 4102 (8.67) */ qnt_pwr = (int)floor(bit_per_dgt * (dgt_nbr - nsd)); /* DGG19 p. 4101 (7) */ - prc_bnr_xpl_rqr = mnt_fabs == 0.0 ? 0 : abs((int)floor(xpn_bs2 - bit_per_dgt*mnt_log10_fabs) - qnt_pwr); /* Protect against mnt = -0.0 */ + prc_bnr_xpl_rqr = mnt_fabs == 0.0 ? 0 : (unsigned short)abs((int)floor(xpn_bs2 - bit_per_dgt*mnt_log10_fabs) - qnt_pwr); /* Protect against mnt = -0.0 */ prc_bnr_xpl_rqr--; /* 20211003 Reduce formula result by 1 bit: Passes all tests, improves CR by ~10% */ bit_xpl_nbr_zro = BIT_XPL_NBR_SGN_FLT - prc_bnr_xpl_rqr; @@ -1491,7 +1491,7 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type, /* 20211003 Continuous determination of dgt_nbr improves CR by ~10% */ dgt_nbr = (int)floor(xpn_bs2 * dgt_per_bit + mnt_log10_fabs) + 1; /* DGG19 p. 4102 (8.67) */ qnt_pwr = (int)floor(bit_per_dgt * (dgt_nbr - nsd)); /* DGG19 p. 4101 (7) */ - prc_bnr_xpl_rqr = mnt_fabs == 0.0 ? 0 : abs((int)floor(xpn_bs2 - bit_per_dgt*mnt_log10_fabs) - qnt_pwr); /* Protect against mnt = -0.0 */ + prc_bnr_xpl_rqr = mnt_fabs == 0.0 ? 0 : (unsigned short)abs((int)floor(xpn_bs2 - bit_per_dgt*mnt_log10_fabs) - qnt_pwr); /* Protect against mnt = -0.0 */ prc_bnr_xpl_rqr--; /* 20211003 Reduce formula result by 1 bit: Passes all tests, improves CR by ~10% */ bit_xpl_nbr_zro = BIT_XPL_NBR_SGN_DBL - prc_bnr_xpl_rqr; diff --git a/libsrc4/ncindex.c b/libsrc4/ncindex.c index 250aa6c5ab..26f407eadc 100644 --- a/libsrc4/ncindex.c +++ b/libsrc4/ncindex.c @@ -162,8 +162,7 @@ int ncindexcount(NCindex* index) { int count = 0; - int i; - for(i=0;i