From 786b03317a76f1d6536a38fb50e23e0aa0c7f5bb Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Mon, 28 Oct 2024 06:58:28 -0700 Subject: [PATCH] Fix remaining calloc param reversals (#5018) gcc 14 identifies likely places where the sizeof() call is used for the first parameter to calloc(). This PR fixes the remaining places in the library where this occurs and reworks a few other allocations to be more uniform. --- hl/src/H5TB.c | 2 +- test/hyperslab.c | 2 +- test/ntypes.c | 40 ++++++------ test/trefer.c | 68 ++++++++++----------- test/trefer_deprec.c | 24 ++++---- test/tselect.c | 97 +++++++++++++++--------------- tools/src/h5repack/h5repack_refs.c | 5 +- tools/test/h5dump/h5dumpgentest.c | 8 +-- tools/test/h5repack/h5repacktst.c | 4 +- 9 files changed, 123 insertions(+), 127 deletions(-) diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c index 842e52b9e69..f94dc26cc5c 100644 --- a/hl/src/H5TB.c +++ b/hl/src/H5TB.c @@ -3185,7 +3185,7 @@ H5TB_create_type(hid_t loc_id, const char *dset_name, size_t type_size, const si if (H5TBget_table_info(loc_id, dset_name, &nfields, NULL) < 0) goto out; - if (NULL == (fnames = (char **)calloc(sizeof(char *), (size_t)nfields))) + if (NULL == (fnames = (char **)calloc((size_t)nfields, sizeof(char *)))) goto out; for (i = 0; i < nfields; i++) diff --git a/test/hyperslab.c b/test/hyperslab.c index 24cef142712..c407facf18a 100644 --- a/test/hyperslab.c +++ b/test/hyperslab.c @@ -985,7 +985,7 @@ test_array_fill(size_t lo, size_t hi) TESTING(s); /* Initialize */ - if (NULL == (dst = (int *)calloc(sizeof(int), ARRAY_FILL_SIZE * hi))) + if (NULL == (dst = (int *)calloc((ARRAY_FILL_SIZE * hi), sizeof(int)))) TEST_ERROR; /* Setup */ diff --git a/test/ntypes.c b/test/ntypes.c index 3fcd40ffb4b..14357087f2a 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -335,9 +335,9 @@ test_compound_dtype2(hid_t file) TESTING("nested compound datatype"); /* Allocate space for the points & check arrays */ - if (NULL == (points = malloc(sizeof(s1) * DIM0 * DIM1))) + if (NULL == (points = (s1 *)malloc((DIM0 * DIM1) * sizeof(s1)))) TEST_ERROR; - if (NULL == (check = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (check = (s1 *)calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; /* Initialize the dataset */ @@ -533,9 +533,9 @@ test_compound_dtype2(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - if (NULL == (tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + if (NULL == (tmp = malloc((DIM0 * DIM1) * H5Tget_size(native_type)))) TEST_ERROR; - if (NULL == (bkg = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (bkg = calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) @@ -648,9 +648,9 @@ test_compound_dtype(hid_t file) TESTING("compound datatype"); /* Allocate space for the points & check arrays */ - if (NULL == (points = malloc(sizeof(s1) * DIM0 * DIM1))) + if (NULL == (points = (s1 *)malloc((DIM0 * DIM1) * sizeof(s1)))) TEST_ERROR; - if (NULL == (check = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (check = (s1 *)calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; /* Initialize the dataset */ @@ -752,9 +752,9 @@ test_compound_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - if (NULL == (tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + if (NULL == (tmp = malloc((DIM0 * DIM1) * H5Tget_size(native_type)))) TEST_ERROR; - if (NULL == (bkg = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (bkg = calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) @@ -856,9 +856,9 @@ test_compound_dtype3(hid_t file) TESTING("compound datatype with array as field"); /* Allocate space for the points & check arrays */ - if (NULL == (points = malloc(sizeof(s1) * DIM0 * DIM1))) + if (NULL == (points = (s1 *)malloc((DIM0 * DIM1) * sizeof(s1)))) TEST_ERROR; - if (NULL == (check = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (check = (s1 *)calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; /* Initialize the dataset */ @@ -980,9 +980,9 @@ test_compound_dtype3(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - if (NULL == (tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + if (NULL == (tmp = malloc((DIM0 * DIM1) * H5Tget_size(native_type)))) TEST_ERROR; - if (NULL == (bkg = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (bkg = calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) @@ -1091,9 +1091,9 @@ test_compound_opaque(hid_t file) TESTING("compound datatype with opaque field"); /* Allocate space for the points & check arrays */ - if (NULL == (points = malloc(sizeof(s1) * DIM0 * DIM1))) + if (NULL == (points = (s1 *)malloc((DIM0 * DIM1) * sizeof(s1)))) TEST_ERROR; - if (NULL == (check = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (check = (s1 *)calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; /* Initialize the dataset */ @@ -1206,9 +1206,9 @@ test_compound_opaque(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - if (NULL == (tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + if (NULL == (tmp = malloc((DIM0 * DIM1) * H5Tget_size(native_type)))) TEST_ERROR; - if (NULL == (bkg = calloc(DIM0 * DIM1, sizeof(s1)))) + if (NULL == (bkg = calloc((DIM0 * DIM1), sizeof(s1)))) TEST_ERROR; if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) @@ -1469,9 +1469,9 @@ test_array_dtype(hid_t file) TESTING("array of compound datatype"); /* Allocate space for the points & check arrays */ - if (NULL == (points = malloc(sizeof(s1) * DIM0 * DIM1 * 5))) + if (NULL == (points = (s1 *)malloc((DIM0 * DIM1 * 5) * sizeof(s1)))) TEST_ERROR; - if (NULL == (check = calloc(DIM0 * DIM1 * 5, sizeof(s1)))) + if (NULL == (check = (s1 *)calloc((DIM0 * DIM1 * 5), sizeof(s1)))) TEST_ERROR; /* Initialize the dataset */ @@ -2428,9 +2428,9 @@ test_refer_dtype2(hid_t file) TESTING("dataset region reference"); /* Allocate write & read buffers */ - if (NULL == (dwbuf = malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2))) + if (NULL == (dwbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)))) TEST_ERROR; - if (NULL == (drbuf = calloc(SPACE2_DIM1 * SPACE2_DIM2, sizeof(uint8_t)))) + if (NULL == (drbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)))) TEST_ERROR; /* Create dataspace for datasets */ diff --git a/test/trefer.c b/test/trefer.c index ac35ea5978f..bc443b7b4be 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -127,7 +127,7 @@ test_reference_params(void) wbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); rbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); tbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - obuf = calloc(SPACE1_DIM1, sizeof(unsigned)); + obuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); for (i = 0; i < SPACE1_DIM1; i++) obuf[i] = i * 3; @@ -468,10 +468,10 @@ test_reference_obj(void) MESSAGE(5, ("Testing Object Reference Functions\n")); /* Allocate write & read buffers */ - wbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - rbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - ibuf = calloc(SPACE1_DIM1, sizeof(unsigned)); - obuf = calloc(SPACE1_DIM1, sizeof(unsigned)); + wbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + rbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + ibuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); + obuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); for (i = 0; i < SPACE1_DIM1; i++) obuf[i] = i * 3; @@ -571,7 +571,7 @@ test_reference_obj(void) VERIFY(obj_type, H5O_TYPE_NAMED_DATATYPE, "H5Rget_obj_type3"); /* Check copying a reference */ - wbuf_cp = calloc(1, sizeof(H5R_ref_t)); + wbuf_cp = (H5R_ref_t *)calloc(1, sizeof(H5R_ref_t)); ret = H5Rcopy(&wbuf[0], &wbuf_cp[0]); CHECK(ret, FAIL, "H5Rcopy"); @@ -838,9 +838,9 @@ test_reference_vlen_obj(void) MESSAGE(5, ("Testing Object Reference Functions within VLEN type\n")); /* Allocate write & read buffers */ - wbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - ibuf = calloc(SPACE1_DIM1, sizeof(unsigned)); - obuf = calloc(SPACE1_DIM1, sizeof(unsigned)); + wbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + ibuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); + obuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); for (i = 0; i < SPACE1_DIM1; i++) obuf[i] = i * 3; @@ -1102,8 +1102,8 @@ test_reference_cmpnd_obj(void) MESSAGE(5, ("Testing Object Reference Functions within compound type\n")); /* Allocate write & read buffers */ - ibuf = calloc(SPACE1_DIM1, sizeof(unsigned)); - obuf = calloc(SPACE1_DIM1, sizeof(unsigned)); + ibuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); + obuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); for (i = 0; i < SPACE1_DIM1; i++) obuf[i] = i * 3; @@ -1411,10 +1411,10 @@ test_reference_region(H5F_libver_t libver_low, H5F_libver_t libver_high) MESSAGE(5, ("Testing Dataset Region Reference Functions\n")); /* Allocate write & read buffers */ - wbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - rbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - dwbuf = (uint8_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); - drbuf = (uint8_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + wbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + rbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + dwbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + drbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); for (tu8 = dwbuf, i = 0; i < (SPACE2_DIM1 * SPACE2_DIM2); i++) *tu8++ = (uint8_t)(i * 3); @@ -1867,10 +1867,10 @@ test_reference_region_1D(H5F_libver_t libver_low, H5F_libver_t libver_high) MESSAGE(5, ("Testing 1-D Dataset Region Reference Functions\n")); /* Allocate write & read buffers */ - wbuf = calloc((size_t)SPACE1_DIM1, sizeof(H5R_ref_t)); - rbuf = calloc((size_t)SPACE1_DIM1, sizeof(H5R_ref_t)); - dwbuf = (uint8_t *)calloc((size_t)SPACE3_DIM1, sizeof(uint8_t)); - drbuf = (uint8_t *)calloc((size_t)SPACE3_DIM1, sizeof(uint8_t)); + wbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + rbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + dwbuf = (uint8_t *)calloc(SPACE3_DIM1, sizeof(uint8_t)); + drbuf = (uint8_t *)calloc(SPACE3_DIM1, sizeof(uint8_t)); for (tu8 = dwbuf, i = 0; i < SPACE3_DIM1; i++) *tu8++ = (uint8_t)(i * 3); @@ -3125,10 +3125,10 @@ test_reference_compat_conv(void) } /* Allocate write & read buffers */ - wbuf_obj = calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); - rbuf_obj = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - wbuf_reg = calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); - rbuf_reg = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + wbuf_obj = (hobj_ref_t *)calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); + rbuf_obj = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + wbuf_reg = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + rbuf_reg = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); /* Create dataspace for datasets */ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL); @@ -3434,17 +3434,17 @@ test_reference_perf(void) MESSAGE(5, ("Testing Object Reference Performance\n")); /* Allocate write & read buffers */ - wbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - obuf = calloc(SPACE1_DIM1, sizeof(unsigned)); - ibuf = calloc(SPACE1_DIM1, sizeof(unsigned)); - wbuf_deprec = calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); - rbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - rbuf_deprec = calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); - tbuf = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - wbuf_reg = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - rbuf_reg = calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); - wbuf_reg_deprec = calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); - rbuf_reg_deprec = calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + wbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + obuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); + ibuf = (unsigned *)calloc(SPACE1_DIM1, sizeof(unsigned)); + wbuf_deprec = (hobj_ref_t *)calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); + rbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + rbuf_deprec = (hobj_ref_t *)calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); + tbuf = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + wbuf_reg = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + rbuf_reg = (H5R_ref_t *)calloc(SPACE1_DIM1, sizeof(H5R_ref_t)); + wbuf_reg_deprec = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + rbuf_reg_deprec = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); for (i = 0; i < SPACE1_DIM1; i++) obuf[i] = i * 3; diff --git a/test/trefer_deprec.c b/test/trefer_deprec.c index 3f932f53b93..d06f5e39ef1 100644 --- a/test/trefer_deprec.c +++ b/test/trefer_deprec.c @@ -623,10 +623,10 @@ test_reference_region(H5F_libver_t libver_low, H5F_libver_t libver_high) MESSAGE(5, ("Testing Dataset Region Reference Functions\n")); /* Allocate write & read buffers */ - wbuf = calloc((size_t)SPACE1_DIM1, sizeof(hdset_reg_ref_t)); - rbuf = malloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); - dwbuf = malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); - drbuf = calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + wbuf = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + rbuf = (hdset_reg_ref_t *)malloc(SPACE1_DIM1 * sizeof(hdset_reg_ref_t)); + dwbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); + drbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); /* Create file access property list */ fapl = H5Pcreate(H5P_FILE_ACCESS); @@ -1064,10 +1064,10 @@ test_reference_region_1D(H5F_libver_t libver_low, H5F_libver_t libver_high) MESSAGE(5, ("Testing 1-D Dataset Region Reference Functions\n")); /* Allocate write & read buffers */ - wbuf = calloc((size_t)SPACE1_DIM1, sizeof(hdset_reg_ref_t)); - rbuf = malloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); - dwbuf = malloc(sizeof(uint8_t) * SPACE3_DIM1); - drbuf = calloc((size_t)SPACE3_DIM1, sizeof(uint8_t)); + wbuf = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + rbuf = (hdset_reg_ref_t *)malloc(SPACE1_DIM1 * sizeof(hdset_reg_ref_t)); + dwbuf = (uint8_t *)malloc(SPACE3_DIM1 * sizeof(uint8_t)); + drbuf = (uint8_t *)calloc(SPACE3_DIM1, sizeof(uint8_t)); /* Create the file access property list */ fapl = H5Pcreate(H5P_FILE_ACCESS); @@ -1636,10 +1636,10 @@ test_reference_compat(void) MESSAGE(5, ("Testing Deprecated Object Reference Functions\n")); /* Allocate write & read buffers */ - wbuf_obj = calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); - rbuf_obj = malloc(sizeof(hobj_ref_t) * SPACE1_DIM1); - wbuf_reg = calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); - rbuf_reg = malloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); + wbuf_obj = (hobj_ref_t *)calloc(SPACE1_DIM1, sizeof(hobj_ref_t)); + rbuf_obj = (hobj_ref_t *)malloc(SPACE1_DIM1 * sizeof(hobj_ref_t)); + wbuf_reg = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + rbuf_reg = (hdset_reg_ref_t *)malloc(SPACE1_DIM1 * sizeof(hdset_reg_ref_t)); /* Create file */ fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); diff --git a/test/tselect.c b/test/tselect.c index 6f9bc6f1426..21c3648d587 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -247,9 +247,9 @@ test_select_hyper(hid_t xfer_plist) MESSAGE(5, ("Testing Hyperslab Selection Functions\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -501,9 +501,9 @@ test_select_point(hid_t xfer_plist) MESSAGE(5, ("Testing Element Selection Functions\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -863,9 +863,9 @@ test_select_all(hid_t xfer_plist) MESSAGE(5, ("Testing 'All' Selection Functions\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE4_DIM1 * SPACE4_DIM2 * SPACE4_DIM3); + wbuf = (uint8_t *)malloc((SPACE4_DIM1 * SPACE4_DIM2 * SPACE4_DIM3) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE4_DIM1 * SPACE4_DIM2 * SPACE4_DIM3), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE4_DIM1 * SPACE4_DIM2 * SPACE4_DIM3), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -950,9 +950,9 @@ test_select_all_hyper(hid_t xfer_plist) MESSAGE(5, ("Testing 'All' Selection Functions\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -1104,9 +1104,9 @@ test_select_combo(void) MESSAGE(5, ("Testing Combination of Hyperslab & Element Selection Functions\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -1299,9 +1299,9 @@ test_select_hyper_stride(hid_t xfer_plist) MESSAGE(5, ("Testing Hyperslabs with Strides Functionality\n")); /* Allocate write & read buffers */ - wbuf = (uint16_t *)malloc(sizeof(uint16_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint16_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint16_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint16_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); + rbuf = (uint16_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -1445,9 +1445,9 @@ test_select_hyper_contig(hid_t dset_type, hid_t xfer_plist) MESSAGE(5, ("Testing Contiguous Hyperslabs Functionality\n")); /* Allocate write & read buffers */ - wbuf = (uint16_t *)malloc(sizeof(uint16_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint16_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint16_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint16_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint16_t)); + rbuf = (uint16_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint16_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -1585,10 +1585,9 @@ test_select_hyper_contig2(hid_t dset_type, hid_t xfer_plist) MESSAGE(5, ("Testing More Contiguous Hyperslabs Functionality\n")); /* Allocate write & read buffers */ - wbuf = (uint16_t *)malloc(sizeof(uint16_t) * SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4); + wbuf = (uint16_t *)malloc((SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4) * sizeof(uint16_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = - (uint16_t *)calloc((size_t)(SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4), sizeof(uint16_t)); + rbuf = (uint16_t *)calloc((SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4), sizeof(uint16_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -1731,10 +1730,9 @@ test_select_hyper_contig3(hid_t dset_type, hid_t xfer_plist) MESSAGE(5, ("Testing Yet More Contiguous Hyperslabs Functionality\n")); /* Allocate write & read buffers */ - wbuf = (uint16_t *)malloc(sizeof(uint16_t) * SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4); + wbuf = (uint16_t *)malloc((SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4) * sizeof(uint16_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = - (uint16_t *)calloc((size_t)(SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4), sizeof(uint16_t)); + rbuf = (uint16_t *)calloc((SPACE8_DIM1 * SPACE8_DIM2 * SPACE8_DIM3 * SPACE8_DIM4), sizeof(uint16_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -3679,11 +3677,11 @@ test_select_hyper_copy(void) MESSAGE(5, ("Testing Hyperslabs with Strides Functionality\n")); /* Allocate write & read buffers */ - wbuf = (uint16_t *)malloc(sizeof(uint16_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint16_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint16_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint16_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); + rbuf = (uint16_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); CHECK_PTR(rbuf, "calloc"); - rbuf2 = (uint16_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); + rbuf2 = (uint16_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); CHECK_PTR(rbuf2, "calloc"); /* Initialize write buffer */ @@ -3850,11 +3848,11 @@ test_select_point_copy(void) MESSAGE(5, ("Testing Hyperslabs with Strides Functionality\n")); /* Allocate write & read buffers */ - wbuf = (uint16_t *)malloc(sizeof(uint16_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint16_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint16_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint16_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); + rbuf = (uint16_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); CHECK_PTR(rbuf, "calloc"); - rbuf2 = (uint16_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); + rbuf2 = (uint16_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint16_t)); CHECK_PTR(rbuf2, "calloc"); /* Initialize write buffer */ @@ -4068,9 +4066,9 @@ test_select_hyper_offset(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with Offsets\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -4276,9 +4274,9 @@ test_select_hyper_offset2(void) MESSAGE(5, ("Testing More Hyperslab Selection Functions with Offsets\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE7_DIM1 * SPACE7_DIM2); + wbuf = (uint8_t *)malloc((SPACE7_DIM1 * SPACE7_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE7_DIM1 * SPACE7_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE7_DIM1 * SPACE7_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -4406,9 +4404,9 @@ test_select_point_offset(void) MESSAGE(5, ("Testing Element Selection Functions\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -4633,9 +4631,9 @@ test_select_hyper_union(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with unions of hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -5411,9 +5409,9 @@ test_select_hyper_union_3d(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with unions of 3-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE4_DIM1 * SPACE4_DIM2 * SPACE4_DIM3); + wbuf = (uint8_t *)malloc((SPACE4_DIM1 * SPACE4_DIM2 * SPACE4_DIM3) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc(SPACE3_DIM1 * SPACE3_DIM2, sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE3_DIM1 * SPACE3_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -5735,9 +5733,9 @@ test_select_hyper_and_2d(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with intersection of 2-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -5874,9 +5872,9 @@ test_select_hyper_xor_2d(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with XOR of 2-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -6015,9 +6013,9 @@ test_select_hyper_notb_2d(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with NOTB of 2-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -6154,9 +6152,9 @@ test_select_hyper_nota_2d(void) MESSAGE(5, ("Testing Hyperslab Selection Functions with NOTA of 2-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc((size_t)(SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -6324,10 +6322,9 @@ test_select_hyper_union_random_5d(hid_t read_plist) MESSAGE(5, ("Testing Hyperslab Selection Functions with random unions of 5-D hyperslabs\n")); /* Allocate write & read buffers */ - wbuf = (int *)malloc(sizeof(int) * SPACE5_DIM1 * SPACE5_DIM2 * SPACE5_DIM3 * SPACE5_DIM4 * SPACE5_DIM5); + wbuf = (int *)malloc((SPACE5_DIM1 * SPACE5_DIM2 * SPACE5_DIM3 * SPACE5_DIM4 * SPACE5_DIM5) * sizeof(int)); CHECK_PTR(wbuf, "malloc"); - rbuf = (int *)calloc((size_t)(SPACE5_DIM1 * SPACE5_DIM2 * SPACE5_DIM3 * SPACE5_DIM4 * SPACE5_DIM5), - sizeof(int)); + rbuf = (int *)calloc((SPACE5_DIM1 * SPACE5_DIM2 * SPACE5_DIM3 * SPACE5_DIM4 * SPACE5_DIM5), sizeof(int)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -7995,9 +7992,9 @@ test_select_none(void) MESSAGE(5, ("Testing I/O on 0-sized Selections\n")); /* Allocate write & read buffers */ - wbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE7_DIM1 * SPACE7_DIM2); + wbuf = (uint8_t *)malloc((SPACE7_DIM1 * SPACE7_DIM2) * sizeof(uint8_t)); CHECK_PTR(wbuf, "malloc"); - rbuf = (uint8_t *)calloc(SPACE7_DIM1 * SPACE7_DIM2, sizeof(uint8_t)); + rbuf = (uint8_t *)calloc((SPACE7_DIM1 * SPACE7_DIM2), sizeof(uint8_t)); CHECK_PTR(rbuf, "calloc"); /* Initialize write buffer */ @@ -13579,7 +13576,7 @@ test_select_hyper_chunk_offset(void) MESSAGE(6, ("Testing hyperslab selections using offsets in chunked datasets\n")); /* Allocate buffers */ - wbuf = (int *)malloc(sizeof(int) * SPACE10_DIM1); + wbuf = (int *)malloc(SPACE10_DIM1 * sizeof(int)); CHECK_PTR(wbuf, "malloc"); rbuf = (int *)calloc(SPACE10_DIM1, sizeof(int)); CHECK_PTR(rbuf, "calloc"); diff --git a/tools/src/h5repack/h5repack_refs.c b/tools/src/h5repack/h5repack_refs.c index bbdc135ffda..0c281b006e8 100644 --- a/tools/src/h5repack/h5repack_refs.c +++ b/tools/src/h5repack/h5repack_refs.c @@ -234,7 +234,7 @@ do_copy_refobjs(hid_t fidin, hid_t fidout, trav_table_t *travt, pack_opt_t *opti *------------------------------------------------------------------------- */ if (nelmts) { - buf = (hdset_reg_ref_t *)malloc((unsigned)(nelmts * msize)); + buf = (hdset_reg_ref_t *)malloc((size_t)(nelmts * msize)); if (buf == NULL) { printf("cannot read into memory\n"); H5TOOLS_GOTO_ERROR((-1), "malloc failed"); @@ -246,8 +246,7 @@ do_copy_refobjs(hid_t fidin, hid_t fidout, trav_table_t *travt, pack_opt_t *opti * create output *------------------------------------------------------------------------- */ - refbuf = (hdset_reg_ref_t *)calloc(sizeof(hdset_reg_ref_t), - (size_t)nelmts); /*init to zero */ + refbuf = (hdset_reg_ref_t *)calloc((size_t)nelmts, sizeof(hdset_reg_ref_t)); if (refbuf == NULL) { printf("cannot allocate memory\n"); H5TOOLS_GOTO_ERROR((-1), "calloc failed"); diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c index 5c13d614844..bac3d9fab1d 100644 --- a/tools/test/h5dump/h5dumpgentest.c +++ b/tools/test/h5dump/h5dumpgentest.c @@ -2254,10 +2254,10 @@ gent_datareg(void) int i; /* counting variables */ /* Allocate write & read buffers */ - wbuf = (hdset_reg_ref_t *)calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1); - rbuf = (hdset_reg_ref_t *)malloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); - dwbuf = (uint8_t *)malloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2); - drbuf = (uint8_t *)calloc(sizeof(uint8_t), SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + rbuf = (hdset_reg_ref_t *)malloc(SPACE1_DIM1 * sizeof(hdset_reg_ref_t)); + dwbuf = (uint8_t *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(uint8_t)); + drbuf = (uint8_t *)calloc((SPACE2_DIM1 * SPACE2_DIM2), sizeof(uint8_t)); /* Create file */ fid1 = H5Fcreate(FILE17, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); diff --git a/tools/test/h5repack/h5repacktst.c b/tools/test/h5repack/h5repacktst.c index e3c34fe82ab..784ebc78651 100644 --- a/tools/test/h5repack/h5repacktst.c +++ b/tools/test/h5repack/h5repacktst.c @@ -4682,8 +4682,8 @@ make_dset_reg_ref(hid_t loc_id) int retval = -1; /* return value */ /* Allocate write & read buffers */ - wbuf = (hdset_reg_ref_t *)calloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1); - dwbuf = (int *)malloc(sizeof(int) * SPACE2_DIM1 * SPACE2_DIM2); + wbuf = (hdset_reg_ref_t *)calloc(SPACE1_DIM1, sizeof(hdset_reg_ref_t)); + dwbuf = (int *)malloc((SPACE2_DIM1 * SPACE2_DIM2) * sizeof(int)); /* Create dataspace for datasets */ if ((sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL)) < 0)