From 5ed255a607d604b45e92b06548682ae9b716535d Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 22 Feb 2021 12:37:12 -0500 Subject: [PATCH] Fixed all -Wincompatible-pointer-types-discards-qualifiers warnings (#341) * Fixed various -Wincompatible-pointer-types-discards-qualifiers warnings by adding const * Fixed various -Wincompatible-pointer-types-discards-qualifiers warning by removing extraneous consts There were casts with const, but the function parameter doesn't actaully take const, so just modified the casts. In the other case, a local variable was const that should not have been, becuase its source wasn't const either. * Fixed a -Wincompatible-pointer-types-discards-qualifiers warning by strdup-ing a string Create a duplicate string instead of mutating a supposedly const one. --- examples/h5_ref_compat.c | 4 ++-- examples/h5_ref_extern.c | 4 ++-- src/H5Dchunk.c | 24 ++++++++++++------------ src/H5Gtest.c | 8 ++++---- src/H5Idbg.c | 8 ++++---- src/H5Ocopy_ref.c | 6 +++--- src/H5Oprivate.h | 2 +- src/H5Shyper.c | 4 ++-- src/H5Sprivate.h | 2 +- tools/lib/h5tools_utils.c | 4 +++- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/examples/h5_ref_compat.c b/examples/h5_ref_compat.c index 82ef525709..cce755bb42 100644 --- a/examples/h5_ref_compat.c +++ b/examples/h5_ref_compat.c @@ -76,9 +76,9 @@ main(void) /* Access reference and read dataset data through new API */ assert(H5Rget_type((const H5R_ref_t *)&new_ref_buf[0]) == H5R_OBJECT2); - H5Rget_obj_type3((const H5R_ref_t *)&new_ref_buf[0], H5P_DEFAULT, &obj_type); + H5Rget_obj_type3(&new_ref_buf[0], H5P_DEFAULT, &obj_type); assert(obj_type == H5O_TYPE_DATASET); - dset1 = H5Ropen_object((const H5R_ref_t *)&new_ref_buf[0], H5P_DEFAULT, H5P_DEFAULT); + dset1 = H5Ropen_object(&new_ref_buf[0], H5P_DEFAULT, H5P_DEFAULT); H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf); H5Dclose(dset1); H5Rdestroy(&new_ref_buf[0]); diff --git a/examples/h5_ref_extern.c b/examples/h5_ref_extern.c index a46f6768cb..691d2358fb 100644 --- a/examples/h5_ref_extern.c +++ b/examples/h5_ref_extern.c @@ -78,9 +78,9 @@ main(void) /* Access reference and read dataset data without opening original file */ assert(H5Rget_type((const H5R_ref_t *)&ref_buf[0]) == H5R_OBJECT2); - H5Rget_obj_type3((const H5R_ref_t *)&ref_buf[0], H5P_DEFAULT, &obj_type); + H5Rget_obj_type3(&ref_buf[0], H5P_DEFAULT, &obj_type); assert(obj_type == H5O_TYPE_DATASET); - dset1 = H5Ropen_object((const H5R_ref_t *)&ref_buf[0], H5P_DEFAULT, H5P_DEFAULT); + dset1 = H5Ropen_object(&ref_buf[0], H5P_DEFAULT, H5P_DEFAULT); H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf); H5Dclose(dset1); H5Rdestroy(&ref_buf[0]); diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index bd3b1edd9f..9d47a4acf6 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -4267,18 +4267,18 @@ H5D__chunk_allocate(const H5D_io_info_t *io_info, hbool_t full_overwrite, hsize_ coordinates) */ hsize_t max_unalloc[H5O_LAYOUT_NDIMS]; /* Last chunk in each dimension that is unallocated (in scaled coordinates) */ - hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Offset of current chunk (in scaled coordinates) */ - size_t orig_chunk_size; /* Original size of chunk in bytes */ - size_t chunk_size; /* Actual size of chunk in bytes, possibly filtered */ - unsigned filter_mask = 0; /* Filter mask for chunks that have them */ - const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */ - const H5O_pline_t * pline = &(dset->shared->dcpl_cache.pline); /* I/O pipeline info */ - const H5O_pline_t def_pline = H5O_CRT_PIPELINE_DEF; /* Default pipeline */ - const H5O_fill_t * fill = &(dset->shared->dcpl_cache.fill); /* Fill value info */ - H5D_fill_value_t fill_status; /* The fill value status */ - hbool_t should_fill = FALSE; /* Whether fill values should be written */ - void * unfilt_fill_buf = NULL; /* Unfiltered fill value buffer */ - void ** fill_buf = NULL; /* Pointer to the fill buffer to use for a chunk */ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Offset of current chunk (in scaled coordinates) */ + size_t orig_chunk_size; /* Original size of chunk in bytes */ + size_t chunk_size; /* Actual size of chunk in bytes, possibly filtered */ + unsigned filter_mask = 0; /* Filter mask for chunks that have them */ + H5O_layout_t * layout = &(dset->shared->layout); /* Dataset layout */ + const H5O_pline_t *pline = &(dset->shared->dcpl_cache.pline); /* I/O pipeline info */ + const H5O_pline_t def_pline = H5O_CRT_PIPELINE_DEF; /* Default pipeline */ + const H5O_fill_t * fill = &(dset->shared->dcpl_cache.fill); /* Fill value info */ + H5D_fill_value_t fill_status; /* The fill value status */ + hbool_t should_fill = FALSE; /* Whether fill values should be written */ + void * unfilt_fill_buf = NULL; /* Unfiltered fill value buffer */ + void ** fill_buf = NULL; /* Pointer to the fill buffer to use for a chunk */ #ifdef H5_HAVE_PARALLEL hbool_t blocks_written = FALSE; /* Flag to indicate that chunk was actually written */ hbool_t using_mpi = diff --git a/src/H5Gtest.c b/src/H5Gtest.c index 5f45c8c89b..9f0dca25e9 100644 --- a/src/H5Gtest.c +++ b/src/H5Gtest.c @@ -553,10 +553,10 @@ done: herr_t H5G__user_path_test(hid_t obj_id, char *user_path, size_t *user_path_len, unsigned *obj_hidden) { - void * obj_ptr; /* Pointer to object for ID */ - H5G_name_t *obj_path; /* Pointer to group hier. path for obj */ - hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ - herr_t ret_value = SUCCEED; /* Return value */ + void * obj_ptr; /* Pointer to object for ID */ + const H5G_name_t *obj_path; /* Pointer to group hier. path for obj */ + hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE diff --git a/src/H5Idbg.c b/src/H5Idbg.c index ea58d591f4..889423045c 100644 --- a/src/H5Idbg.c +++ b/src/H5Idbg.c @@ -76,10 +76,10 @@ static int H5I__id_dump_cb(void *_item, void *_key, void *_udata); static int H5I__id_dump_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata) { - H5I_id_info_t *info = (H5I_id_info_t *)_item; /* Pointer to the ID node */ - H5I_type_t type = *(H5I_type_t *)_udata; /* User data */ - H5G_name_t * path = NULL; /* Path to file object */ - const void * object = NULL; /* Pointer to VOL connector object */ + H5I_id_info_t * info = (H5I_id_info_t *)_item; /* Pointer to the ID node */ + H5I_type_t type = *(H5I_type_t *)_udata; /* User data */ + const H5G_name_t *path = NULL; /* Path to file object */ + const void * object = NULL; /* Pointer to VOL connector object */ FUNC_ENTER_STATIC_NOERR diff --git a/src/H5Ocopy_ref.c b/src/H5Ocopy_ref.c index f2372c1ace..f1f8aaf62c 100644 --- a/src/H5Ocopy_ref.c +++ b/src/H5Ocopy_ref.c @@ -63,7 +63,7 @@ static herr_t H5O__copy_expand_ref_object1(H5O_loc_t *src_oloc, const void *buf_ static herr_t H5O__copy_expand_ref_region1(H5O_loc_t *src_oloc, const void *buf_src, H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, void *buf_dst, size_t ref_count, H5O_copy_t *cpy_info); -static herr_t H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, H5T_t *dt_src, +static herr_t H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, const H5T_t *dt_src, const void *buf_src, size_t nbytes_src, H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, void *buf_dst, size_t ref_count, H5O_copy_t *cpy_info); @@ -284,7 +284,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, H5T_t *dt_src, const void *buf_src, +H5O__copy_expand_ref_object2(H5O_loc_t *src_oloc, hid_t tid_src, const H5T_t *dt_src, const void *buf_src, size_t nbytes_src, H5O_loc_t *dst_oloc, H5G_loc_t *dst_root_loc, void *buf_dst, size_t ref_count, H5O_copy_t *cpy_info) { @@ -423,7 +423,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5O_copy_expand_ref(H5F_t *file_src, hid_t tid_src, H5T_t *dt_src, void *buf_src, size_t nbytes_src, +H5O_copy_expand_ref(H5F_t *file_src, hid_t tid_src, const H5T_t *dt_src, void *buf_src, size_t nbytes_src, H5F_t *file_dst, void *buf_dst, H5O_copy_t *cpy_info) { H5O_loc_t dst_oloc; /* Copied object object location */ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index b6bd3fe033..5b4c11bfda 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -994,7 +994,7 @@ H5_DLL herr_t H5O_are_mdc_flushes_disabled(H5O_loc_t *oloc, hbool_t *are_disable H5_DLL herr_t H5O_copy_header_map(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, H5O_copy_t *cpy_info, hbool_t inc_depth, H5O_type_t *obj_type, void **udata); -H5_DLL herr_t H5O_copy_expand_ref(H5F_t *file_src, hid_t tid_src, H5T_t *dt_src, void *buf_src, +H5_DLL herr_t H5O_copy_expand_ref(H5F_t *file_src, hid_t tid_src, const H5T_t *dt_src, void *buf_src, size_t nbytes_src, H5F_t *file_dst, void *buf_dst, H5O_copy_t *cpy_info); /* Debugging routines */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 87776611fd..e12ff93574 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -10273,7 +10273,7 @@ done: Specify a hyperslab to combine with the current hyperslab selection, and store the result in the new hyperslab selection. USAGE - herr_t H5S_combine_hyperslab(new_space, old_space, op, start, stride, count, block) + herr_t H5S_combine_hyperslab(old_space, op, start, stride, count, block, new_space) H5S_t *old_space; IN: The old space the selection is performed on H5S_seloper_t op; IN: Operation to perform on current selection const hsize_t start[]; IN: Offset of start of hyperslab @@ -10297,7 +10297,7 @@ done: REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_combine_hyperslab(H5S_t *old_space, H5S_seloper_t op, const hsize_t start[], const hsize_t *stride, +H5S_combine_hyperslab(const H5S_t *old_space, H5S_seloper_t op, const hsize_t start[], const hsize_t *stride, const hsize_t count[], const hsize_t *block, H5S_t **new_space) { unsigned u; /* Local index variable */ diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index f5e4f2c2f5..738d9ae3df 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -276,7 +276,7 @@ H5_DLL herr_t H5S_select_elements(H5S_t *space, H5S_seloper_t op, size_t num_ele /* Operations on hyperslab selections */ H5_DLL herr_t H5S_select_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], const hsize_t *stride, const hsize_t count[], const hsize_t *block); -H5_DLL herr_t H5S_combine_hyperslab(H5S_t *old_space, H5S_seloper_t op, const hsize_t start[], +H5_DLL herr_t H5S_combine_hyperslab(const H5S_t *old_space, H5S_seloper_t op, const hsize_t start[], const hsize_t *stride, const hsize_t count[], const hsize_t *block, H5S_t **new_space); H5_DLL herr_t H5S_hyper_add_span_element(H5S_t *space, unsigned rank, const hsize_t *coords); diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index 70b715a2d4..bee6262406 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -196,7 +196,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti /* long command line option */ int i; const char ch = '='; - char * arg = &argv[opt_ind][2]; + char * arg = HDstrdup(&argv[opt_ind][2]); size_t arg_len = 0; opt_arg = strchr(&argv[opt_ind][2], ch); @@ -253,6 +253,8 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti opt_ind++; sp = 1; + + HDfree(arg); } else { register char *cp; /* pointer into current token */