summaryrefslogtreecommitdiffstats
path: root/tools/test/misc
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2021-11-23 14:09:05 (GMT)
committerGitHub <noreply@github.com>2021-11-23 14:09:05 (GMT)
commit462e9a373f810eda51f4bc3c6415d6130b2a3cac (patch)
treedf3d2687c84d9be85bb758ee48f5ee15c7578799 /tools/test/misc
parentb9e4deec10cc943a7ecb3ac6bc6bd6695b2f33a0 (diff)
downloadhdf5-462e9a373f810eda51f4bc3c6415d6130b2a3cac.zip
hdf5-462e9a373f810eda51f4bc3c6415d6130b2a3cac.tar.gz
hdf5-462e9a373f810eda51f4bc3c6415d6130b2a3cac.tar.bz2
Create 2D arrays on the heap in a different way (#1169)
* Create 2D arrays on the heap by malloc'ing `struct { TYPE arr[ROWS][COLS]; }`. This avoids the double-indirection through pointers and the additional memory of H5TEST_ALLOCATE_2D_ARRAY(). This change will safely quiet the cast warning that PR #1129 was intended to fix. * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'tools/test/misc')
-rw-r--r--tools/test/misc/h5clear_gentest.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/tools/test/misc/h5clear_gentest.c b/tools/test/misc/h5clear_gentest.c
index 53fbc42..923c3f2 100644
--- a/tools/test/misc/h5clear_gentest.c
+++ b/tools/test/misc/h5clear_gentest.c
@@ -56,24 +56,26 @@ const char *FILENAME_ENHANCE[] = {
static int
gen_cache_image_file(const char *fname)
{
- hid_t fid = H5I_INVALID_HID; /* File ID */
- hid_t did = -1, sid = H5I_INVALID_HID; /* Dataset ID, dataspace ID */
- hid_t fapl = H5I_INVALID_HID; /* File access property list */
- hid_t dcpl = H5I_INVALID_HID; /* Dataset creation property list */
- hsize_t dims[2]; /* Dimension sizes */
- hsize_t chunks[2]; /* Chunked dimension sizes */
- int i, j; /* Local index variables */
- int ** buf = NULL; /* Buffer for data to write */
- H5AC_cache_image_config_t cache_image_config = /* Cache image input configuration */
+ hid_t fid = H5I_INVALID_HID; /* File ID */
+ hid_t did = -1, sid = H5I_INVALID_HID; /* Dataset ID, dataspace ID */
+ hid_t fapl = H5I_INVALID_HID; /* File access property list */
+ hid_t dcpl = H5I_INVALID_HID; /* Dataset creation property list */
+ hsize_t dims[2]; /* Dimension sizes */
+ hsize_t chunks[2]; /* Chunked dimension sizes */
+ int i, j; /* Local index variables */
+ struct {
+ int arr[50][100];
+ } * buf; /* Buffer for data to write */
+ H5AC_cache_image_config_t cache_image_config = /* Cache image input configuration */
{H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION, TRUE, FALSE, H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE};
/* Create and fill array */
- H5TEST_ALLOCATE_2D_ARRAY(buf, int, 50, 100);
+ buf = malloc(sizeof(*buf));
if (NULL == buf)
goto error;
for (i = 0; i < 50; i++)
for (j = 0; j < 100; j++)
- buf[i][j] = i * j;
+ buf->arr[i][j] = i * j;
/* Create a copy of file access property list */
if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
@@ -108,7 +110,7 @@ gen_cache_image_file(const char *fname)
goto error;
/* Write to the dataset */
- if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
+ if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
goto error;
/* Closing */