Skip to content

Commit

Permalink
Hdf5 1 12 Miscellaneous warnings fixes (HDFGroup#1718)
Browse files Browse the repository at this point in the history
* Fixes const issues in the version 2 B-trees (HDFGroup#1172)

The operations that were changed are fundamentally not const since the
shadow operation can modify the node structure when SWMR is in use.

* Quiets const warning in H5RS code (HDFGroup#1181)

* Avoid calling H5Ropen_object with a misaligned H5R_ref_t: copy the (HDFGroup#1171)

* Avoid calling H5Ropen_object with a misaligned H5R_ref_t: copy the
raw H5R_ref_t bytes to a heap buffer that's known to have the right
alignment.

* Committing clang-format changes

* Use an automatic H5R_ref_t instead of malloc'ing one.  Go ahead and
initialize the H5R_ref_t to all-0s so that arbitrary stack content
doesn't foul things up.  Bail out with an error if `size` exceeds
`sizeof(H5R_ref_t)`.

* Committing clang-format changes

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Miscellaneous warnings fixes

Co-authored-by: Dana Robinson <[email protected]>
Co-authored-by: David Young <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed May 8, 2022
1 parent f9c844c commit 6d1a640
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 52 deletions.
13 changes: 5 additions & 8 deletions hl/src/H5PT.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static H5I_type_t H5PT_ptable_id_type = H5I_UNINIT;
#define H5PT_HASH_TABLE_SIZE 64

/* Packet Table private functions */
static herr_t H5PT_free_id(void *id, void **_ctx);
static herr_t H5PT_free_id(void *id);
static herr_t H5PT_close(htbl_t *table);
static herr_t H5PT_create_index(htbl_t *table_id);
static herr_t H5PT_set_index(htbl_t *table_id, hsize_t pt_index);
Expand Down Expand Up @@ -87,8 +87,7 @@ H5PTcreate(hid_t loc_id, const char *dset_name, hid_t dtype_id, hsize_t chunk_si

/* Register the packet table ID type if this is the first table created */
if (H5PT_ptable_id_type < 0)
if ((H5PT_ptable_id_type =
H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
if ((H5PT_ptable_id_type = H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, H5PT_free_id)) < 0)
goto error;

/* Get memory for the table identifier */
Expand Down Expand Up @@ -208,8 +207,7 @@ H5PTcreate_fl(hid_t loc_id, const char *dset_name, hid_t dtype_id, hsize_t chunk

/* Register the packet table ID type if this is the first table created */
if (H5PT_ptable_id_type < 0)
if ((H5PT_ptable_id_type =
H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
if ((H5PT_ptable_id_type = H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, H5PT_free_id)) < 0)
goto error;

/* Get memory for the table identifier */
Expand Down Expand Up @@ -323,8 +321,7 @@ H5PTopen(hid_t loc_id, const char *dset_name)

/* Register the packet table ID type if this is the first table created */
if (H5PT_ptable_id_type < 0)
if ((H5PT_ptable_id_type =
H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
if ((H5PT_ptable_id_type = H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, H5PT_free_id)) < 0)
goto error;

table = (htbl_t *)HDmalloc(sizeof(htbl_t));
Expand Down Expand Up @@ -402,7 +399,7 @@ H5PTopen(hid_t loc_id, const char *dset_name)
*-------------------------------------------------------------------------
*/
static herr_t
H5PT_free_id(void *id, void H5_ATTR_UNUSED **_ctx)
H5PT_free_id(void *id)
{
HDfree(id);
return SUCCEED;
Expand Down
33 changes: 15 additions & 18 deletions src/H5B2int.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
/********************/
/* Local Prototypes */
/********************/
static herr_t H5B2__update_child_flush_depends(H5B2_hdr_t *hdr, unsigned depth,
const H5B2_node_ptr_t *node_ptrs, unsigned start_idx,
unsigned end_idx, void *old_parent, void *new_parent);
static herr_t H5B2__update_child_flush_depends(H5B2_hdr_t *hdr, unsigned depth, H5B2_node_ptr_t *node_ptrs,
unsigned start_idx, unsigned end_idx, void *old_parent,
void *new_parent);

/*********************/
/* Package Variables */
Expand Down Expand Up @@ -1617,7 +1617,7 @@ H5B2__insert(H5B2_hdr_t *hdr, void *udata)
*-------------------------------------------------------------------------
*/
herr_t
H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_node, void *parent,
H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node, void *parent,
H5B2_operator_t op, void *op_data)
{
const H5AC_class_t *curr_node_class = NULL; /* Pointer to current node's class info */
Expand All @@ -1642,8 +1642,7 @@ H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_

/* Lock the current B-tree node */
if (NULL ==
(internal = H5B2__protect_internal(hdr, parent, (H5B2_node_ptr_t *)curr_node, depth, FALSE,
H5AC__READ_ONLY_FLAG))) /* Casting away const OK -QAK */
(internal = H5B2__protect_internal(hdr, parent, curr_node, depth, FALSE, H5AC__READ_ONLY_FLAG)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree internal node")

/* Set up information about current node */
Expand Down Expand Up @@ -1739,8 +1738,8 @@ H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_
*-------------------------------------------------------------------------
*/
herr_t
H5B2__delete_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_node, void *parent,
H5B2_remove_t op, void *op_data)
H5B2__delete_node(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node, void *parent, H5B2_remove_t op,
void *op_data)
{
const H5AC_class_t *curr_node_class = NULL; /* Pointer to current node's class info */
void * node = NULL; /* Pointers to current node */
Expand All @@ -1759,8 +1758,7 @@ H5B2__delete_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_n

/* Lock the current B-tree node */
if (NULL ==
(internal = H5B2__protect_internal(hdr, parent, (H5B2_node_ptr_t *)curr_node, depth, FALSE,
H5AC__NO_FLAGS_SET))) /* Casting away const OK -QAK */
(internal = H5B2__protect_internal(hdr, parent, curr_node, depth, FALSE, H5AC__NO_FLAGS_SET)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree internal node")

/* Set up information about current node */
Expand Down Expand Up @@ -1824,7 +1822,7 @@ H5B2__delete_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_n
*-------------------------------------------------------------------------
*/
herr_t
H5B2__node_size(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_node, void *parent,
H5B2__node_size(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node, void *parent,
hsize_t *btree_size)
{
H5B2_internal_t *internal = NULL; /* Pointer to internal node */
Expand All @@ -1839,8 +1837,8 @@ H5B2__node_size(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_nod
HDassert(depth > 0);

/* Lock the current B-tree node */
if (NULL == (internal = H5B2__protect_internal(hdr, parent, (H5B2_node_ptr_t *)curr_node, depth, FALSE,
H5AC__READ_ONLY_FLAG))) /* Casting away const OK -QAK */
if (NULL ==
(internal = H5B2__protect_internal(hdr, parent, curr_node, depth, FALSE, H5AC__READ_ONLY_FLAG)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree internal node")

/* Recursively descend into child nodes, if we are above the "twig" level in the B-tree */
Expand Down Expand Up @@ -1910,7 +1908,7 @@ H5B2__create_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry)
*-------------------------------------------------------------------------
*/
herr_t
H5B2__update_flush_depend(H5B2_hdr_t *hdr, unsigned depth, const H5B2_node_ptr_t *node_ptr, void *old_parent,
H5B2__update_flush_depend(H5B2_hdr_t *hdr, unsigned depth, H5B2_node_ptr_t *node_ptr, void *old_parent,
void *new_parent)
{
const H5AC_class_t *child_class; /* Pointer to child node's class info */
Expand Down Expand Up @@ -1941,9 +1939,8 @@ H5B2__update_flush_depend(H5B2_hdr_t *hdr, unsigned depth, const H5B2_node_ptr_t
H5B2_internal_t *child_int;

/* Protect child */
if (NULL == (child_int = H5B2__protect_internal(
hdr, new_parent, (H5B2_node_ptr_t *)node_ptr, (uint16_t)(depth - 1), FALSE,
H5AC__NO_FLAGS_SET))) /* Casting away const OK -QAK */
if (NULL == (child_int = H5B2__protect_internal(hdr, new_parent, node_ptr, (uint16_t)(depth - 1),
FALSE, H5AC__NO_FLAGS_SET)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree internal node")
child_class = H5AC_BT2_INT;
child = child_int;
Expand Down Expand Up @@ -2010,7 +2007,7 @@ H5B2__update_flush_depend(H5B2_hdr_t *hdr, unsigned depth, const H5B2_node_ptr_t
*-------------------------------------------------------------------------
*/
static herr_t
H5B2__update_child_flush_depends(H5B2_hdr_t *hdr, unsigned depth, const H5B2_node_ptr_t *node_ptrs,
H5B2__update_child_flush_depends(H5B2_hdr_t *hdr, unsigned depth, H5B2_node_ptr_t *node_ptrs,
unsigned start_idx, unsigned end_idx, void *old_parent, void *new_parent)
{
unsigned u; /* Local index variable */
Expand Down
12 changes: 6 additions & 6 deletions src/H5B2pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ extern const H5B2_class_t *const H5B2_client_class_g[H5B2_NUM_BTREE_ID];

/* Generic routines */
H5_DLL herr_t H5B2__create_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry);
H5_DLL herr_t H5B2__update_flush_depend(H5B2_hdr_t *hdr, unsigned depth, const H5B2_node_ptr_t *node_ptr,
H5_DLL herr_t H5B2__update_flush_depend(H5B2_hdr_t *hdr, unsigned depth, H5B2_node_ptr_t *node_ptr,
void *old_parent, void *new_parent);
H5_DLL herr_t H5B2__destroy_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry);

Expand Down Expand Up @@ -390,9 +390,9 @@ H5_DLL herr_t H5B2__update_leaf(H5B2_hdr_t *hdr, H5B2_node_ptr_t *curr_node_ptr,
void *op_data);

/* Routines for iterating over nodes/records */
H5_DLL herr_t H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_node,
void *parent, H5B2_operator_t op, void *op_data);
H5_DLL herr_t H5B2__node_size(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_node, void *parent,
H5_DLL herr_t H5B2__iterate_node(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node, void *parent,
H5B2_operator_t op, void *op_data);
H5_DLL herr_t H5B2__node_size(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node, void *parent,
hsize_t *op_data);

/* Routines for locating records */
Expand Down Expand Up @@ -423,8 +423,8 @@ H5_DLL herr_t H5B2__remove_leaf_by_idx(H5B2_hdr_t *hdr, H5B2_node_ptr_t *curr_no
void *op_data);

/* Routines for deleting nodes */
H5_DLL herr_t H5B2__delete_node(H5B2_hdr_t *hdr, uint16_t depth, const H5B2_node_ptr_t *curr_node,
void *parent, H5B2_remove_t op, void *op_data);
H5_DLL herr_t H5B2__delete_node(H5B2_hdr_t *hdr, uint16_t depth, H5B2_node_ptr_t *curr_node, void *parent,
H5B2_remove_t op, void *op_data);

/* Debugging routines for dumping file structures */
H5_DLL herr_t H5B2__hdr_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth,
Expand Down
7 changes: 2 additions & 5 deletions src/H5Dchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5180,14 +5180,11 @@ H5D__chunk_collective_fill(const H5D_t *dset, H5D_chunk_coll_fill_info_t *chunk_
static int
H5D__chunk_cmp_coll_fill_info(const void *_entry1, const void *_entry2)
{
const struct chunk_coll_fill_info *entry1;
const struct chunk_coll_fill_info *entry2;
const struct chunk_coll_fill_info *entry1 = (const struct chunk_coll_fill_info *)_entry1;
const struct chunk_coll_fill_info *entry2 = (const struct chunk_coll_fill_info *)_entry2;

FUNC_ENTER_STATIC_NOERR

entry1 = (const struct chunk_coll_fill_info *)_entry1;
entry2 = (const struct chunk_coll_fill_info *)_entry2;

FUNC_LEAVE_NOAPI(H5F_addr_cmp(entry1->addr, entry2->addr))
} /* end H5D__chunk_cmp_coll_fill_info() */
#endif /* H5_HAVE_PARALLEL */
Expand Down
4 changes: 2 additions & 2 deletions src/H5FDhdfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ H5FD_hdfs_init(void)
}

herr_t
H5Pget_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa_out)
H5Pget_fapl_hdfs(hid_t H5_ATTR_UNUSED fapl_id, H5FD_hdfs_fapl_t H5_ATTR_UNUSED *fa_out)
{
herr_t ret_value = FAIL;

Expand All @@ -1745,7 +1745,7 @@ H5Pget_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa_out)
}

herr_t
H5Pset_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa)
H5Pset_fapl_hdfs(hid_t H5_ATTR_UNUSED fapl_id, H5FD_hdfs_fapl_t H5_ATTR_UNUSED *fa)
{
herr_t ret_value = FAIL;

Expand Down
2 changes: 1 addition & 1 deletion src/H5Gname.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ H5G_build_fullpath(const char *prefix, const char *name)
/* Build full path */
HDstrncpy(full_path, prefix, orig_path_len + 1);
if (need_sep)
HDstrncat(full_path, "/", (size_t)1);
HDstrcat(full_path, "/");
HDstrncat(full_path, name, name_len);

/* Create reference counted string for path */
Expand Down
12 changes: 10 additions & 2 deletions src/H5RS.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,16 @@ H5RS_wrap(const char *s)
if (NULL == (ret_value = H5FL_MALLOC(H5RS_str_t)))
HGOTO_ERROR(H5E_RS, H5E_NOSPACE, NULL, "memory allocation failed")

/* Set the internal fields */
ret_value->s = (char *)s;
/* Set the internal fields
*
* We ignore warnings about storing a const char pointer in the struct
* since we never modify or free the string when the wrapped struct
* field is set to TRUE.
*/
H5_GCC_DIAG_OFF("cast-qual")
ret_value->s = (char *)s;
H5_GCC_DIAG_ON("cast-qual")

ret_value->wrapped = 1;
ret_value->n = 1;

Expand Down
15 changes: 9 additions & 6 deletions src/H5trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ H5_trace(const double *returning, const char *func, const char *type, ...)
void * vp = NULL;
FILE * out = H5_debug_g.trace;
static hbool_t is_first_invocation = TRUE;
H5_timer_t function_timer = {{0}, {0}, {0}, FALSE};
H5_timevals_t function_times;
H5_timer_t function_timer;
H5_timevals_t function_times = {0.0, 0.0, 0.0};
static H5_timer_t running_timer;
H5_timevals_t running_times;
static int current_depth = 0;
Expand All @@ -130,6 +130,10 @@ H5_trace(const double *returning, const char *func, const char *type, ...)
return 0.0F; /*tracing is off*/
HDva_start(ap, type);

/* Initialize the timer for this function */
if (H5_debug_g.ttimes)
H5_timer_init(&function_timer);

if (H5_debug_g.ttop) {
if (returning) {
if (current_depth > 1) {
Expand All @@ -153,11 +157,10 @@ H5_trace(const double *returning, const char *func, const char *type, ...)
H5_timer_init(&running_timer);
H5_timer_start(&running_timer);
} /* end if */
if (H5_debug_g.ttimes) {
/* start the timer for this function */
H5_timer_init(&function_timer);

/* Start the timer for this function */
if (H5_debug_g.ttimes)
H5_timer_start(&function_timer);
} /* end if */

/* Print the first part of the line. This is the indication of the
* nesting depth followed by the function name and either start of
Expand Down
4 changes: 3 additions & 1 deletion test/chunk_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ test_get_chunk_info_highest18(hid_t fapl)
unsigned filter_mask = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
int fillvalue = -1; /* Fill value */
int aggression = 9; /* Compression aggression setting */
#ifdef H5_HAVE_FILTER_DEFLATE
int aggression = 9; /* Compression aggression setting */
#endif
H5F_libver_t low, high; /* File format bounds */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
Expand Down
2 changes: 1 addition & 1 deletion test/trefstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ test_refstr_cmp(void)
H5RS_str_t *rs1; /* Ref-counted string created */
H5RS_str_t *rs2; /* Ref-counted string created */
int cmp; /* Comparison value */
size_t len; /* Length of string */
ssize_t len; /* Length of string */
herr_t ret; /* Generic return value */

/* Output message about test being performed */
Expand Down
5 changes: 3 additions & 2 deletions testpar/t_span_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "H5Spkg.h" /* Dataspaces */
#include "testphdf5.h"

#define LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG 0

static void coll_write_test(int chunk_factor);
static void coll_read_test(int chunk_factor);

Expand Down Expand Up @@ -1430,8 +1432,7 @@ lower_dim_size_comp_test__verify_data(uint32_t *buf_ptr,
*-------------------------------------------------------------------------
*/

#define LDSCT_DS_RANK 5
#define LOWER_DIM_SIZE_COMP_TEST__RUN_TEST__DEBUG 0
#define LDSCT_DS_RANK 5

static void
lower_dim_size_comp_test__run_test(const int chunk_edge_size, const hbool_t use_collective_io,
Expand Down
3 changes: 3 additions & 0 deletions tools/lib/h5diff_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,9 @@ character_compare_opt(unsigned char *mem1, unsigned char *mem2, hsize_t elemtno,
hbool_t both_zero = FALSE;
double per;

/* both_zero is set in the PER_UNSIGN macro but not used in this function */
(void)both_zero;

HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char));
HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char));
H5TOOLS_START_DEBUG(" %d=%d", temp1_uchar, temp2_uchar);
Expand Down

0 comments on commit 6d1a640

Please sign in to comment.