Skip to content

Commit

Permalink
Silence conversion warnings in libsrc4
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Mar 15, 2024
1 parent 5973f3d commit d8e29bd
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 58 deletions.
2 changes: 1 addition & 1 deletion libsrc4/nc4attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions libsrc4/nc4cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions libsrc4/nc4dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__));

Expand All @@ -52,7 +51,7 @@ NC4_inq_unlimdim(int ncid, int *unlimdimidp)
*unlimdimidp = -1;
for (g = grp; g && !found; g = g->parent)
{
for(i=0;i<ncindexsize(grp->dim);i++)
for(size_t i=0;i<ncindexsize(grp->dim);i++)
{
dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
if(dim == NULL) continue;
Expand Down Expand Up @@ -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));

Expand All @@ -190,7 +188,7 @@ NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
/* Get our dim info. */
assert(h5);
{
for(i=0;i<ncindexsize(grp->dim);i++)
for(size_t i=0;i<ncindexsize(grp->dim);i++)
{
dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
if(dim == NULL) continue;
Expand Down
13 changes: 5 additions & 8 deletions libsrc4/nc4grp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;i<ncindexsize(grp->children);i++)
for(size_t i=0;i<ncindexsize(grp->children);i++)
{
g = (NC_GRP_INFO_T*)ncindexith(grp->children,i);
if(g == NULL) continue;
Expand Down Expand Up @@ -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));

Expand All @@ -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;
Expand Down Expand Up @@ -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;i<ncindexsize(grp->dim);i++) {
for(size_t i=0;i<ncindexsize(grp->dim);i++) {
dim = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
if(dim == NULL) continue;
dimids[n++] = dim->hdr.id;
Expand All @@ -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;i<ncindexsize(g->dim);i++) {
for(size_t i=0;i<ncindexsize(g->dim);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. */
Expand Down
57 changes: 26 additions & 31 deletions libsrc4/nc4internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -562,7 +561,7 @@ nc4_rec_find_named_type(NC_GRP_INFO_T *start_grp, char *name)
return type;

/* Search subgroups. */
for(i=0;i<ncindexsize(start_grp->children);i++) {
for(size_t i=0;i<ncindexsize(start_grp->children);i++) {
g = (NC_GRP_INFO_T*)ncindexith(start_grp->children,i);
if(g == NULL) continue;
if ((res = nc4_rec_find_named_type(g, name)))
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -1490,42 +1488,41 @@ 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);
LOG((3, "%s: grp->name %s", __func__, grp->hdr.name));

/* 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);
Expand All @@ -1551,33 +1548,31 @@ 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);
LOG((3, "%s: grp->name %s", __func__, grp->hdr.name));

/* 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;j<ncindexsize(v->att);j++) {
for(size_t j=0;j<ncindexsize(v->att);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;
Expand All @@ -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);
}

Expand Down
5 changes: 2 additions & 3 deletions libsrc4/nc4type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -74,8 +74,7 @@ NC4_inq_typeids(int ncid, int *ntypes, int *typeids)

/* Count types. */
if (grp->type) {
int i;
for(i=0;i<ncindexsize(grp->type);i++)
for(size_t i=0;i<ncindexsize(grp->type);i++)
{
if((type = (NC_TYPE_INFO_T*)ncindexith(grp->type,i)) == NULL) continue;
if (typeids)
Expand Down
Loading

0 comments on commit d8e29bd

Please sign in to comment.