summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorjhendersonHDF <jhenderson@hdfgroup.org>2022-05-01 20:54:41 (GMT)
committerGitHub <noreply@github.com>2022-05-01 20:54:41 (GMT)
commit2ba7a01bfff451b043e2ec00811c0aad78921545 (patch)
tree31dc785e35a95578ea9fbb491fbc931e62234302 /test
parent5eba258d90aa89c3d1d58f1b5ef93c1cf9821c29 (diff)
downloadhdf5-2ba7a01bfff451b043e2ec00811c0aad78921545.zip
hdf5-2ba7a01bfff451b043e2ec00811c0aad78921545.tar.gz
hdf5-2ba7a01bfff451b043e2ec00811c0aad78921545.tar.bz2
Fix some const cast and stack/static object size warnings (#1700)
* Fix various warnings * Move HDfree_const to H5private.h for wider use * Print output from all ranks in parallel tests on allocation failure * Move const pointer freeing macro to h5test.h for now
Diffstat (limited to 'test')
-rw-r--r--test/h5test.h9
-rw-r--r--test/vds_env.c51
-rw-r--r--test/vfd.c16
3 files changed, 56 insertions, 20 deletions
diff --git a/test/h5test.h b/test/h5test.h
index 7b82b68..5c3e9a3 100644
--- a/test/h5test.h
+++ b/test/h5test.h
@@ -193,6 +193,15 @@ H5TEST_DLLVAR MPI_Info h5_io_info_g; /* MPI INFO object for IO */
extern "C" {
#endif
+/*
+ * Ugly hack to cast away const for freeing const-qualified pointers.
+ * Should only be used sparingly, where the alternative (like keeping
+ * an equivalent non-const pointer around) is far messier.
+ */
+#ifndef h5_free_const
+#define h5_free_const(mem) HDfree((void *)(uintptr_t)mem)
+#endif
+
/* Generally useful testing routines */
H5TEST_DLL void h5_clean_files(const char *base_name[], hid_t fapl);
H5TEST_DLL int h5_cleanup(const char *base_name[], hid_t fapl);
diff --git a/test/vds_env.c b/test/vds_env.c
index e01f2e0..97aa245 100644
--- a/test/vds_env.c
+++ b/test/vds_env.c
@@ -44,13 +44,13 @@ const char *FILENAME[] = {"vds_env_virt_0", "vds_env_virt_3", "vds_env_src_2", "
static int
test_vds_prefix_second(unsigned config, hid_t fapl)
{
- char srcfilename[FILENAME_BUF_SIZE];
- char srcfilename_map[FILENAME_BUF_SIZE];
- char vfilename[FILENAME_BUF_SIZE];
- char vfilename2[FILENAME_BUF_SIZE];
- char srcfilenamepct[FILENAME_BUF_SIZE];
- char srcfilenamepct_map[FILENAME_BUF_SIZE];
const char *srcfilenamepct_map_orig = "vds%%%%_src";
+ char * srcfilename = NULL;
+ char * srcfilename_map = NULL;
+ char * vfilename = NULL;
+ char * vfilename2 = NULL;
+ char * srcfilenamepct = NULL;
+ char * srcfilenamepct_map = NULL;
hid_t srcfile[4] = {-1, -1, -1, -1}; /* Files with source dsets */
hid_t vfile = -1; /* File with virtual dset */
hid_t dcpl = -1; /* Dataset creation property list */
@@ -69,12 +69,25 @@ test_vds_prefix_second(unsigned config, hid_t fapl)
TESTING("basic virtual dataset I/O via H5Pset_vds_prefix(): all selection with ENV prefix")
- h5_fixname(FILENAME[0], fapl, vfilename, sizeof vfilename);
- h5_fixname(FILENAME[1], fapl, vfilename2, sizeof vfilename2);
- h5_fixname(FILENAME[2], fapl, srcfilename, sizeof srcfilename);
- h5_fixname_printf(FILENAME[2], fapl, srcfilename_map, sizeof srcfilename_map);
- h5_fixname(FILENAME[3], fapl, srcfilenamepct, sizeof srcfilenamepct);
- h5_fixname_printf(srcfilenamepct_map_orig, fapl, srcfilenamepct_map, sizeof srcfilenamepct_map);
+ if (NULL == (srcfilename = HDmalloc(FILENAME_BUF_SIZE)))
+ TEST_ERROR
+ if (NULL == (srcfilename_map = HDmalloc(FILENAME_BUF_SIZE)))
+ TEST_ERROR
+ if (NULL == (vfilename = HDmalloc(FILENAME_BUF_SIZE)))
+ TEST_ERROR
+ if (NULL == (vfilename2 = HDmalloc(FILENAME_BUF_SIZE)))
+ TEST_ERROR
+ if (NULL == (srcfilenamepct = HDmalloc(FILENAME_BUF_SIZE)))
+ TEST_ERROR
+ if (NULL == (srcfilenamepct_map = HDmalloc(FILENAME_BUF_SIZE)))
+ TEST_ERROR
+
+ h5_fixname(FILENAME[0], fapl, vfilename, FILENAME_BUF_SIZE);
+ h5_fixname(FILENAME[1], fapl, vfilename2, FILENAME_BUF_SIZE);
+ h5_fixname(FILENAME[2], fapl, srcfilename, FILENAME_BUF_SIZE);
+ h5_fixname_printf(FILENAME[2], fapl, srcfilename_map, FILENAME_BUF_SIZE);
+ h5_fixname(FILENAME[3], fapl, srcfilenamepct, FILENAME_BUF_SIZE);
+ h5_fixname_printf(srcfilenamepct_map_orig, fapl, srcfilenamepct_map, FILENAME_BUF_SIZE);
/* create tmp directory and get current working directory path */
if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST)
@@ -260,10 +273,24 @@ test_vds_prefix_second(unsigned config, hid_t fapl)
TEST_ERROR
dcpl = -1;
+ HDfree(srcfilenamepct_map);
+ HDfree(srcfilenamepct);
+ HDfree(vfilename2);
+ HDfree(vfilename);
+ HDfree(srcfilename_map);
+ HDfree(srcfilename);
+
PASSED();
return 0;
error:
+ HDfree(srcfilenamepct_map);
+ HDfree(srcfilenamepct);
+ HDfree(vfilename2);
+ HDfree(vfilename);
+ HDfree(srcfilename_map);
+ HDfree(srcfilename);
+
H5E_BEGIN_TRY
{
for (i = 0; i < (int)(sizeof(srcdset) / sizeof(srcdset[0])); i++)
diff --git a/test/vfd.c b/test/vfd.c
index b1b176a..b3bbf43 100644
--- a/test/vfd.c
+++ b/test/vfd.c
@@ -4112,7 +4112,7 @@ test_vector_io__setup_v(uint32_t count, H5FD_mem_t types[], haddr_t addrs[], siz
if (write_bufs[i]) {
- HDfree((void *)write_bufs[i]);
+ h5_free_const(write_bufs[i]);
write_bufs[i] = NULL;
}
@@ -4256,7 +4256,7 @@ test_vector_io__setup_fixed_size_v(uint32_t count, H5FD_mem_t types[], haddr_t a
if (write_bufs[i]) {
- HDfree((void *)write_bufs[i]);
+ h5_free_const(write_bufs[i]);
write_bufs[i] = NULL;
}
@@ -4922,13 +4922,13 @@ test_vector_io(const char *vfd_name)
for (i = 0; i < count; i++) {
- HDfree((void *)write_bufs_0[i]);
+ h5_free_const(write_bufs_0[i]);
write_bufs_0[i] = NULL;
- HDfree((void *)write_bufs_1[i]);
+ h5_free_const(write_bufs_1[i]);
write_bufs_1[i] = NULL;
- HDfree((void *)write_bufs_2[i]);
+ h5_free_const(write_bufs_2[i]);
write_bufs_2[i] = NULL;
HDfree(read_bufs_0[i]);
@@ -4940,13 +4940,13 @@ test_vector_io(const char *vfd_name)
HDfree(read_bufs_2[i]);
read_bufs_2[i] = NULL;
- HDfree((void *)f_write_bufs_0[i]);
+ h5_free_const(f_write_bufs_0[i]);
f_write_bufs_0[i] = NULL;
- HDfree((void *)f_write_bufs_1[i]);
+ h5_free_const(f_write_bufs_1[i]);
f_write_bufs_1[i] = NULL;
- HDfree((void *)f_write_bufs_2[i]);
+ h5_free_const(f_write_bufs_2[i]);
f_write_bufs_2[i] = NULL;
HDfree(f_read_bufs_0[i]);