Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence most warnings in libhdf5 #2874

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nc4internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ typedef struct NC_ATT_INFO
{
NC_OBJ hdr; /**< The hdr contains the name and ID. */
struct NC_OBJ *container; /**< Pointer to containing group|var. */
int len; /**< Length of attribute data. */
size_t len; /**< Length of attribute data. */
nc_bool_t dirty; /**< True if attribute modified. */
nc_bool_t created; /**< True if attribute already created. */
nc_type nc_typeid; /**< NetCDF type of attribute's data. */
Expand Down
13 changes: 5 additions & 8 deletions libhdf5/hdf5attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp,
{
NC_VAR_INFO_T *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->hdr.id == varid);

Expand Down Expand Up @@ -92,14 +92,13 @@ nc4_get_att_special(NC_FILE_INFO_T* h5, const char* name,
return NC_EATTMETA;

if(strcmp(name,NCPROPS)==0) {
int len;
if(h5->provenance.ncproperties == NULL)
return NC_ENOTATT;
if(mem_type == NC_NAT) mem_type = NC_CHAR;
if(mem_type != NC_CHAR)
return NC_ECHAR;
if(filetypep) *filetypep = NC_CHAR;
len = strlen(h5->provenance.ncproperties);
size_t len = strlen(h5->provenance.ncproperties);
if(lenp) *lenp = len;
if(data) strncpy((char*)data,h5->provenance.ncproperties,len+1);
} else if(strcmp(name,ISNETCDF4ATT)==0
Expand All @@ -110,7 +109,7 @@ nc4_get_att_special(NC_FILE_INFO_T* h5, const char* name,
if(strcmp(name,SUPERBLOCKATT)==0)
iv = (unsigned long long)h5->provenance.superblockversion;
else /* strcmp(name,ISNETCDF4ATT)==0 */
iv = NC4_isnetcdf4(h5);
iv = (unsigned long long)NC4_isnetcdf4(h5);
if(mem_type == NC_NAT) mem_type = NC_INT;
if(data)
switch (mem_type) {
Expand Down Expand Up @@ -271,8 +270,6 @@ NC4_HDF5_del_att(int ncid, int varid, const char *name)
NC_ATT_INFO_T *att;
NCindex* attlist = NULL;
hid_t locid = 0;
int i;
size_t deletedid;
int retval;

/* Name must be provided. */
Expand Down Expand Up @@ -328,7 +325,7 @@ NC4_HDF5_del_att(int ncid, int varid, const char *name)
return NC_EATTMETA;
}

deletedid = att->hdr.id;
int deletedid = att->hdr.id;

/* reclaim associated HDF5 info */
if((retval=nc4_HDF5_close_att(att))) return retval;
Expand All @@ -338,7 +335,7 @@ NC4_HDF5_del_att(int ncid, int varid, const char *name)
return retval;

/* Renumber all attributes with higher indices. */
for (i = 0; i < ncindexsize(attlist); i++)
for (size_t i = 0; i < ncindexsize(attlist); i++)
{
NC_ATT_INFO_T *a;
if (!(a = (NC_ATT_INFO_T *)ncindexith(attlist, i)))
Expand Down
8 changes: 4 additions & 4 deletions libhdf5/hdf5create.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
{
NCglobalstate* gs = NC_getglobalstate();
if(gs->alignment.defined) {
if (H5Pset_alignment(fapl_id, gs->alignment.threshold, gs->alignment.alignment) < 0) {
if (H5Pset_alignment(fapl_id, (hsize_t)gs->alignment.threshold, (hsize_t)gs->alignment.alignment) < 0) {
BAIL(NC_EHDFERR);
}
}
Expand Down Expand Up @@ -222,12 +222,12 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
if(nc4_info->mem.diskless) {
size_t alloc_incr; /* Buffer allocation increment */
size_t min_incr = 65536; /* Minimum buffer increment */
double buf_prcnt = 0.1f; /* Percentage of buffer size to set as increment */
double buf_prcnt = 0.1; /* Percentage of buffer size to set as increment */
/* set allocation increment to a percentage of the supplied buffer size, or
* a pre-defined minimum increment value, whichever is larger
*/
if ((buf_prcnt * initialsz) > min_incr)
alloc_incr = (size_t)(buf_prcnt * initialsz);
if ((size_t)(buf_prcnt * (double)initialsz) > min_incr)
alloc_incr = (size_t)(buf_prcnt * (double)initialsz);
else
alloc_incr = min_incr;
/* Configure FAPL to use the core file driver */
Expand Down
3 changes: 1 addition & 2 deletions libhdf5/hdf5dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ HDF5_def_dim(int ncid, const char *name, size_t len, int *idp)
NC_DIM_INFO_T *dim;
char norm_name[NC_MAX_NAME + 1];
int retval = NC_NOERR;
int i;

LOG((2, "%s: ncid 0x%x name %s len %d", __func__, ncid, name,
(int)len));
Expand All @@ -65,7 +64,7 @@ HDF5_def_dim(int ncid, const char *name, size_t len, int *idp)
{
/* Only one limited dimenson for strict nc3. */
if (len == NC_UNLIMITED) {
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;
if (dim->unlimited)
Expand Down
17 changes: 7 additions & 10 deletions libhdf5/hdf5file.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "hdf5internal.h"
#include "ncrc.h"
#include "ncauth.h"
#include <sys/types.h>

extern int NC4_extract_file_image(NC_FILE_INFO_T* h5, int abort); /* In nc4memcb.c */

Expand Down Expand Up @@ -51,10 +52,9 @@ detect_preserve_dimids(NC_GRP_INFO_T *grp, nc_bool_t *bad_coord_orderp)
NC_GRP_INFO_T *child_grp;
int last_dimid = -1;
int retval;
int i;

/* Iterate over variables in this group */
for (i=0; i < ncindexsize(grp->vars); i++)
for (size_t i=0; i < ncindexsize(grp->vars); i++)
{
NC_HDF5_VAR_INFO_T *hdf5_var;
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,i);
Expand Down Expand Up @@ -98,7 +98,7 @@ detect_preserve_dimids(NC_GRP_INFO_T *grp, nc_bool_t *bad_coord_orderp)
}

/* If there are any child groups, check them also for this condition. */
for (i = 0; i < ncindexsize(grp->children); i++)
for (size_t i = 0; i < ncindexsize(grp->children); i++)
{
if (!(child_grp = (NC_GRP_INFO_T *)ncindexith(grp->children, i)))
continue;
Expand Down Expand Up @@ -326,15 +326,14 @@ static void
dumpopenobjects(NC_FILE_INFO_T* h5)
{
NC_HDF5_FILE_INFO_T *hdf5_info;
int nobjs;

assert(h5 && h5->format_file_info);
hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;

if(hdf5_info->hdfid <= 0)
return; /* File was never opened */

nobjs = H5Fget_obj_count(hdf5_info->hdfid, H5F_OBJ_ALL);
ssize_t nobjs = H5Fget_obj_count(hdf5_info->hdfid, H5F_OBJ_ALL);

/* Apparently we can get an error even when nobjs == 0 */
if(nobjs < 0) {
Expand All @@ -346,7 +345,7 @@ dumpopenobjects(NC_FILE_INFO_T* h5)
* objects open, which means there's a bug in the library. So
* print out some info on to help the poor programmer figure it
* out. */
snprintf(msg,sizeof(msg),"There are %d HDF5 objects open!", nobjs);
snprintf(msg,sizeof(msg),"There are %zd HDF5 objects open!", nobjs);
#ifdef LOGGING
#ifdef LOGOPEN
LOG((0, msg));
Expand Down Expand Up @@ -485,7 +484,6 @@ NC4_enddef(int ncid)
NC_FILE_INFO_T *nc4_info;
NC_GRP_INFO_T *grp;
int retval;
int i;
NC_VAR_INFO_T* var = NULL;

LOG((1, "%s: ncid 0x%x", __func__, ncid));
Expand All @@ -497,7 +495,7 @@ NC4_enddef(int ncid)
/* Why is this here? Especially since it is not recursive so it
only applies to the this grp */
/* When exiting define mode, mark all variable written. */
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);
assert(var);
Expand Down Expand Up @@ -658,7 +656,6 @@ NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
NC_FILE_INFO_T *h5;
NC_GRP_INFO_T *grp;
int retval;
int i;

LOG((2, "%s: ncid 0x%x", __func__, ncid));

Expand Down Expand Up @@ -697,7 +694,7 @@ NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
with netcdf-3, then only the last unlimited one will be reported
back in xtendimp. */
/* Note that this code is inconsistent with nc_inq_unlimid() */
for(i=0;i<ncindexsize(grp->dim);i++) {
for(size_t i=0;i<ncindexsize(grp->dim);i++) {
NC_DIM_INFO_T* d = (NC_DIM_INFO_T*)ncindexith(grp->dim,i);
if(d == NULL) continue;
if(d->unlimited) {
Expand Down
35 changes: 13 additions & 22 deletions libhdf5/hdf5internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ find_var_dim_max_length(NC_GRP_INFO_T *grp, int varid, int dimid,
LOG((3, "find_var_dim_max_length varid %d dimid %d", varid, dimid));

/* Find this 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->hdr.id == varid);

Expand Down Expand Up @@ -252,21 +252,20 @@ nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len)
{
NC_VAR_INFO_T *var;
int retval;
int i;

assert(grp && len);
LOG((3, "%s: grp->name %s dimid %d", __func__, grp->hdr.name, dimid));

/* If there are any groups, call this function recursively on
* them. */
for (i = 0; i < ncindexsize(grp->children); i++)
for (size_t i = 0; i < ncindexsize(grp->children); i++)
if ((retval = nc4_find_dim_len((NC_GRP_INFO_T*)ncindexith(grp->children, i),
dimid, len)))
return retval;

/* For all variables in this group, find the ones that use this
* dimension, and remember the max length. */
for (i = 0; i < ncindexsize(grp->vars); i++)
for (size_t i = 0; i < ncindexsize(grp->vars); i++)
{
size_t mylen;
var = (NC_VAR_INFO_T *)ncindexith(grp->vars, i);
Expand Down Expand Up @@ -431,23 +430,21 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim)
{
int dims_detached = 0;
int finished = 0;
int d;

/* Loop over all dimensions for variable. */
for (d = 0; d < var->ndims && !finished; d++)
for (unsigned int d = 0; d < var->ndims && !finished; d++)
{
/* Is there a dimscale attached to this axis? */
if (hdf5_var->dimscale_attached[d])
{
NC_GRP_INFO_T *g;
int k;

for (g = grp; g && !finished; g = g->parent)
{
NC_DIM_INFO_T *dim1;
NC_HDF5_DIM_INFO_T *hdf5_dim1;

for (k = 0; k < ncindexsize(g->dim); k++)
for (size_t k = 0; k < ncindexsize(g->dim); k++)
{
dim1 = (NC_DIM_INFO_T *)ncindexith(g->dim, k);
assert(dim1 && dim1->format_dim_info);
Expand Down Expand Up @@ -542,9 +539,8 @@ static int
close_gatts(NC_GRP_INFO_T *grp)
{
NC_ATT_INFO_T *att;
int a;

for (a = 0; a < ncindexsize(grp->att); a++)
for (size_t a = 0; a < ncindexsize(grp->att); a++)
{
att = (NC_ATT_INFO_T *)ncindexith(grp->att, a);
assert(att && att->format_att_info);
Expand Down Expand Up @@ -595,9 +591,8 @@ close_vars(NC_GRP_INFO_T *grp)
NC_VAR_INFO_T *var;
NC_HDF5_VAR_INFO_T *hdf5_var;
NC_ATT_INFO_T *att;
int a, i;

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);
assert(var && var->format_var_info);
Expand Down Expand Up @@ -631,7 +626,7 @@ close_vars(NC_GRP_INFO_T *grp)
nc4_HDF5_close_type(var->type_info);
}

for (a = 0; a < ncindexsize(var->att); a++)
for (size_t a = 0; a < ncindexsize(var->att); a++)
{
att = (NC_ATT_INFO_T *)ncindexith(var->att, a);
assert(att && att->format_att_info);
Expand Down Expand Up @@ -669,9 +664,8 @@ static int
close_dims(NC_GRP_INFO_T *grp)
{
NC_DIM_INFO_T *dim;
int i;

for (i = 0; i < ncindexsize(grp->dim); i++)
for (size_t i = 0; i < ncindexsize(grp->dim); i++)
{
NC_HDF5_DIM_INFO_T *hdf5_dim;

Expand Down Expand Up @@ -704,9 +698,7 @@ close_dims(NC_GRP_INFO_T *grp)
static int
close_types(NC_GRP_INFO_T *grp)
{
int i;

for (i = 0; i < ncindexsize(grp->type); i++)
for (size_t i = 0; i < ncindexsize(grp->type); i++)
{
NC_TYPE_INFO_T *type;

Expand Down Expand Up @@ -764,7 +756,6 @@ int
nc4_rec_grp_HDF5_del(NC_GRP_INFO_T *grp)
{
NC_HDF5_GRP_INFO_T *hdf5_grp;
int i;
int retval;

assert(grp && grp->format_grp_info);
Expand All @@ -774,7 +765,7 @@ nc4_rec_grp_HDF5_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_HDF5_del((NC_GRP_INFO_T *)ncindexith(grp->children,
i))))
return retval;
Expand Down Expand Up @@ -905,7 +896,7 @@ nc4_hdf5_find_grp_var_att(int ncid, int varid, const char *name, int attnum,
}
else
{
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;

/* Do we need to read the var attributes? */
Expand Down Expand Up @@ -935,7 +926,7 @@ nc4_hdf5_find_grp_var_att(int ncid, int varid, const char *name, int attnum,
if (att)
{
my_att = use_name ? (NC_ATT_INFO_T *)ncindexlookup(attlist, my_norm_name) :
(NC_ATT_INFO_T *)ncindexith(attlist, attnum);
(NC_ATT_INFO_T *)ncindexith(attlist, (size_t)attnum);
if (!my_att)
return NC_ENOTATT;
}
Expand Down
Loading
Loading