From 7add52ff4f2443357648d53d52add274d1b18b5f Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Wed, 20 Mar 2019 14:03:48 -0500 Subject: Fixed HDFFV-10210 and HDFFV-10587 Description: - Added parameter validation (HDFFV-10210) - Added detection of division by zero (HDFFV-10587 - CVE-2018-17438) - Fixed typos in various tests Platforms tested: Linux/64 (jelly) Linux/64 (platypus) Darwin (osx1011test) --- c++/test/tobject.cpp | 4 ++-- src/H5Dselect.c | 2 ++ src/H5I.c | 3 +++ test/tid.c | 15 +++++++++++++++ test/titerate.c | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index 537716f..23c1453 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -609,10 +609,10 @@ static void test_getobjectinfo_same_file() catch (Exception& E) { cerr << " in Exception " << E.getCFuncName() << "detail: " << E.getCDetailMsg() << endl; - issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_getobjectinfo_same_file()", __LINE__, __FILE__, E.getCDetailMsg()); } -} // test_h5o_getinfo_same_file +} // test_getobjectinfo_same_file /*------------------------------------------------------------------------- * Function: test_object diff --git a/src/H5Dselect.c b/src/H5Dselect.c index 0ec3423..4ffce62 100644 --- a/src/H5Dselect.c +++ b/src/H5Dselect.c @@ -227,6 +227,8 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, /* Decrement number of elements left to process */ HDassert(((size_t)tmp_file_len % elmt_size) == 0); + if(elmt_size == 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "Resulted in division by zero") nelmts -= ((size_t)tmp_file_len / elmt_size); } /* end while */ } /* end else */ diff --git a/src/H5I.c b/src/H5I.c index ca9ff61..345c010 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -355,6 +355,9 @@ H5Itype_exists(H5I_type_t type) FUNC_ENTER_API(FAIL) H5TRACE1("t", "It", type); + if(H5I_IS_LIB_TYPE(type)) + HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "cannot call public function on library type") + if (type <= H5I_BADID || type >= H5I_next_type) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number") diff --git a/test/tid.c b/test/tid.c index 8a27c3b..d2bcdc4 100644 --- a/test/tid.c +++ b/test/tid.c @@ -224,6 +224,21 @@ static int basic_id_test(void) goto out; H5E_END_TRY + /* Test that H5Itype_exists cannot be called on library types because + * it is a public function + */ + H5E_BEGIN_TRY + err = H5Itype_exists(H5I_GROUP); + if(err >= 0) + goto out; + H5E_END_TRY + + H5E_BEGIN_TRY + err = H5Itype_exists(H5I_ATTR); + if(err >= 0) + goto out; + H5E_END_TRY + return 0; out: diff --git a/test/titerate.c b/test/titerate.c index 87ddfb8..5fad1b4 100644 --- a/test/titerate.c +++ b/test/titerate.c @@ -946,7 +946,7 @@ find_err_msg_cb(unsigned n, const H5E_error2_t *err_desc, void *_client_data) if (searched_err == NULL) return -1; - + /* If the searched error message is found, stop the iteration */ if (err_desc->desc != NULL && strcmp(err_desc->desc, searched_err->message) == 0) { -- cgit v0.12 From 97cdcc47e4291394d136121554f8d5130ab19bd4 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 21 Mar 2019 01:15:09 -0700 Subject: Used the H5_INC_ENUM macro to squash enum value increment warnings. --- test/dsets.c | 12 ++++++------ test/dtypes.c | 20 ++++++++++---------- test/objcopy.c | 4 ++-- test/ohdr.c | 4 ++-- test/set_extent.c | 4 ++-- test/tfile.c | 30 +++++++++++++++--------------- test/th5o.c | 4 ++-- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index 5de9cfa..ef3cf58 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -835,8 +835,8 @@ test_compact_io(hid_t fapl) skipping invalid combinations. - Create a file, create and write a compact dataset, and verify its data - Verify the dataset's layout and fill message versions */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Set version bounds */ H5E_BEGIN_TRY { @@ -10331,8 +10331,8 @@ test_zero_dim_dset(hid_t fapl) /* Loop through all the combinations of low/high library format bounds, skipping invalid combination, and verify support for reading a 1D chunked dataset with dimension size = 0 */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Set version bounds before opening the file */ H5E_BEGIN_TRY { @@ -12961,8 +12961,8 @@ test_versionbounds(void) /* Create a source file and a dataset in it. Create a virtual file and virtual dataset. Creation of virtual dataset should only succeed in H5F_LIBVER_V110 */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Set version bounds, skip for invalid low/high combination */ H5E_BEGIN_TRY { diff --git a/test/dtypes.c b/test/dtypes.c index 7e5a992..a39603d 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -6837,8 +6837,8 @@ test_delete_obj_named(hid_t fapl) /* Loop through all valid the combinations of low/high library format bounds, to test delete objects that use named datatypes through different file IDs */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Skip invalid low/high combination */ if ((high == H5F_LIBVER_EARLIEST) || (low > high)) @@ -6938,8 +6938,8 @@ test_delete_obj_named_fileid(hid_t fapl) h5_fixname(FILENAME[9], fapl2, filename2, sizeof filename2); /* Loop through all the combinations of low/high library format bounds */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Skip invalid low/high combination */ if ((high == H5F_LIBVER_EARLIEST) || (low > high)) @@ -7691,19 +7691,19 @@ test_versionbounds(void) ret = H5Tenum_insert(enum_type, "RED", &enum_val); if (ret < 0) TEST_ERROR - enum_val++; + H5_INC_ENUM(color_t, enum_val); ret = H5Tenum_insert(enum_type, "GREEN", &enum_val); if (ret < 0) TEST_ERROR - enum_val++; + H5_INC_ENUM(color_t, enum_val); ret = H5Tenum_insert(enum_type, "BLUE", &enum_val); if (ret < 0) TEST_ERROR - enum_val++; + H5_INC_ENUM(color_t, enum_val); ret = H5Tenum_insert(enum_type, "ORANGE", &enum_val); if (ret < 0) TEST_ERROR - enum_val++; + H5_INC_ENUM(color_t, enum_val); ret = H5Tenum_insert(enum_type, "YELLOW", &enum_val); if (ret < 0) TEST_ERROR @@ -7727,8 +7727,8 @@ test_versionbounds(void) skipping invalid combinations */ /* Create the file, create and write to a dataset with compound datatype */ /* Verify the dataset's datatype and its members */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Set version bounds */ H5E_BEGIN_TRY { diff --git a/test/objcopy.c b/test/objcopy.c index 4055781..f526f7b 100644 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -2197,8 +2197,8 @@ test_copy_dataset_versionbounds(hid_t fcpl_src, hid_t fapl_src) /* Loop through all the combinations of low/high library format bounds, skipping invalid combinations. Create a destination file and copy the source dataset to it, then verify */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Set version bounds */ H5E_BEGIN_TRY { diff --git a/test/ohdr.c b/test/ohdr.c index 85554a5..b8f7112 100644 --- a/test/ohdr.c +++ b/test/ohdr.c @@ -1716,8 +1716,8 @@ main(void) api_ctx_pushed = TRUE; /* Loop through all the combinations of low/high library format bounds */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { char *low_string = NULL; char *high_string = NULL; diff --git a/test/set_extent.c b/test/set_extent.c index 5d11819..f6b02cf 100644 --- a/test/set_extent.c +++ b/test/set_extent.c @@ -433,8 +433,8 @@ static int do_layouts( hid_t fapl ) TESTING("storage layout use - tested with all low/high library format bounds"); /* Loop through all the combinations of low/high library format bounds */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Copy plist to use locally to avoid modifying the original */ new_fapl = H5Pcopy(fapl); diff --git a/test/tfile.c b/test/tfile.c index c5e913c..e3ff372 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -5148,7 +5148,7 @@ test_libver_bounds_open(void) /* Opening VERBFNAME in these combination should succeed. For each low bound, verify that it is upgraded properly */ high = H5F_LIBVER_LATEST; - for (low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) + for (low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { H5F_libver_t new_low = H5F_LIBVER_EARLIEST; @@ -5241,8 +5241,8 @@ test_libver_bounds_low_high(void) CHECK(fapl, FAIL, "H5Pcreate"); /* Loop through all the combinations of low/high version bounds */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { H5E_BEGIN_TRY { /* Set the low/high version bounds */ @@ -5610,8 +5610,8 @@ test_libver_bounds_super_open(hid_t fapl, hid_t fcpl, htri_t is_swmr) CHECK(new_fapl, FAIL, "H5Pcreate"); /* Loop through all the combinations of low/high bounds in new_fapl */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { H5E_BEGIN_TRY { ret = H5Pset_libver_bounds(new_fapl, low, high); } H5E_END_TRY; @@ -5782,8 +5782,8 @@ test_libver_bounds_obj(hid_t fapl) /* Loop through all the combinations of low/high bounds in new_fapl */ /* Open the file with the fapl; create a group and verify the object header version, then delete the group and close the file.*/ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { H5E_BEGIN_TRY { ret = H5Pset_libver_bounds(new_fapl, low, high); } H5E_END_TRY; @@ -5993,8 +5993,8 @@ test_libver_bounds_dataset(hid_t fapl) /* Loop through all the combinations of low/high bounds in new_fapl */ /* Open the file with the fapl and create the chunked dataset */ /* Verify the dataset's layout, fill value and filter pipleline message versions */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { H5E_BEGIN_TRY { ret = H5Pset_libver_bounds(new_fapl, low, high); } H5E_END_TRY; @@ -6206,8 +6206,8 @@ test_libver_bounds_dataspace(hid_t fapl) /* Loop through all the combinations of low/high bounds in new_fapl */ /* Open the file and create the chunked/compact/contiguous datasets */ /* Verify the dataspace message version for the three datasets */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { hid_t tmp_sid, tmp_sid_compact, tmp_sid_contig; /* Dataspace IDs */ H5S_t *tmp_space, *tmp_space_compact, *tmp_space_contig; /* Internal dataspace pointers */ @@ -6531,8 +6531,8 @@ test_libver_bounds_datatype_check(hid_t fapl, hid_t tid) /* Open the file and create the chunked dataset with the input tid */ /* Verify the dataset's datatype message version */ /* Also verify the committed atatype message version */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { H5E_BEGIN_TRY { ret = H5Pset_libver_bounds(new_fapl, low, high); } H5E_END_TRY; @@ -6852,8 +6852,8 @@ test_libver_bounds_attributes(hid_t fapl) /* Loop through all the combinations of low/high bounds */ /* Open the file and group and attach an attribute to the group */ /* Verify the attribute version */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { H5E_BEGIN_TRY { ret = H5Pset_libver_bounds(new_fapl, low, high); } H5E_END_TRY; diff --git a/test/th5o.c b/test/th5o.c index 63fee5f..0aa589f 100644 --- a/test/th5o.c +++ b/test/th5o.c @@ -806,8 +806,8 @@ test_h5o_link(void) CHECK(fapl_id, FAIL, "H5Pcreate"); /* Loop through all the combinations of low/high library format bounds */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; low++) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; high++) { + for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { + for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { /* Set version bounds */ H5E_BEGIN_TRY { -- cgit v0.12 From fe104cc38ffbdb39d3e04da107d86ebfc7e8b622 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Thu, 21 Mar 2019 11:09:17 -0500 Subject: Test improvement Description Moved the new tests to a more appropriate test function. Platforms tested: Linux/64 (jelly) --- test/tid.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/test/tid.c b/test/tid.c index d2bcdc4..7f61c6a 100644 --- a/test/tid.c +++ b/test/tid.c @@ -224,21 +224,6 @@ static int basic_id_test(void) goto out; H5E_END_TRY - /* Test that H5Itype_exists cannot be called on library types because - * it is a public function - */ - H5E_BEGIN_TRY - err = H5Itype_exists(H5I_GROUP); - if(err >= 0) - goto out; - H5E_END_TRY - - H5E_BEGIN_TRY - err = H5Itype_exists(H5I_ATTR); - if(err >= 0) - goto out; - H5E_END_TRY - return 0; out: @@ -266,7 +251,10 @@ static int id_predefined_test(void ) testObj = HDmalloc(sizeof(int)); - /* Try to perform illegal functions on various predefined types */ + /* + * Attempt to perform public functions on various library types + */ + H5E_BEGIN_TRY testID = H5Iregister(H5I_FILE, testObj); H5E_END_TRY @@ -307,7 +295,26 @@ static int id_predefined_test(void ) if(testErr >= 0) goto out; - /* Create a datatype ID and try to perform illegal functions on it */ + H5E_BEGIN_TRY + testErr = H5Itype_exists(H5I_GROUP); + H5E_END_TRY + + VERIFY(testErr, -1, "H5Itype_exists"); + if(testErr != -1) + goto out; + + H5E_BEGIN_TRY + testErr = H5Itype_exists(H5I_ATTR); + H5E_END_TRY + + VERIFY(testErr, -1, "H5Itype_exists"); + if(testErr != -1) + goto out; + + /* + * Create a datatype ID and try to perform illegal functions on it + */ + typeID = H5Tcreate(H5T_OPAQUE, (size_t)42); CHECK(typeID, H5I_INVALID_HID, "H5Tcreate"); if(typeID == H5I_INVALID_HID) @@ -332,7 +339,7 @@ static int id_predefined_test(void ) H5Tclose(typeID); /* testObj was never registered as an atom, so it will not be - * automatically freed. */ + * automatically freed. */ HDfree(testObj); return 0; -- cgit v0.12 From ef8aa13174da60265381112fc68cf6563a338f72 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 21 Mar 2019 10:09:55 -0700 Subject: Changes that show the right way to iterate over enums. --- test/dtypes.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/dtypes.c b/test/dtypes.c index a39603d..1a2f4d0 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -7627,7 +7627,10 @@ test_versionbounds(void) H5F_t *filep = NULL; /* Pointer to internal structure of a file */ H5T_t *dtypep = NULL; /* Pointer to internal structure of a datatype */ hsize_t arr_dim[] = {ARRAY_LEN}; /* Length of the array */ + int i, j; /* Indices for iterating over versions */ H5F_libver_t low, high; /* File format bounds */ + H5F_libver_t versions[] = {H5F_LIBVER_EARLIEST, H5F_LIBVER_V18, H5F_LIBVER_V110}; + int versions_count = 3; /* Number of version bounds in the array */ unsigned highest_version; /* Highest version in nested datatypes */ color_t enum_val; /* Enum type index */ herr_t ret = 0; /* Generic return value */ @@ -7691,19 +7694,19 @@ test_versionbounds(void) ret = H5Tenum_insert(enum_type, "RED", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_GREEN; ret = H5Tenum_insert(enum_type, "GREEN", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_BLUE; ret = H5Tenum_insert(enum_type, "BLUE", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_ORANGE; ret = H5Tenum_insert(enum_type, "ORANGE", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_YELLOW; ret = H5Tenum_insert(enum_type, "YELLOW", &enum_val); if (ret < 0) TEST_ERROR @@ -7727,8 +7730,13 @@ test_versionbounds(void) skipping invalid combinations */ /* Create the file, create and write to a dataset with compound datatype */ /* Verify the dataset's datatype and its members */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { + for(i = 0; i < versions_count; i++) { + + low = versions[i]; + + for(j = 0; high < versions_count; j++) { + + high = versions[j]; /* Set version bounds */ H5E_BEGIN_TRY { -- cgit v0.12 From 85e2214d55a3845ce78f2e4ff5f67b160d773dcb Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 21 Mar 2019 10:09:55 -0700 Subject: Changes that show the right way to iterate over enums. --- test/dtypes.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/dtypes.c b/test/dtypes.c index a39603d..2056245 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -7627,7 +7627,10 @@ test_versionbounds(void) H5F_t *filep = NULL; /* Pointer to internal structure of a file */ H5T_t *dtypep = NULL; /* Pointer to internal structure of a datatype */ hsize_t arr_dim[] = {ARRAY_LEN}; /* Length of the array */ + int i, j; /* Indices for iterating over versions */ H5F_libver_t low, high; /* File format bounds */ + H5F_libver_t versions[] = {H5F_LIBVER_EARLIEST, H5F_LIBVER_V18, H5F_LIBVER_V110}; + int versions_count = 3; /* Number of version bounds in the array */ unsigned highest_version; /* Highest version in nested datatypes */ color_t enum_val; /* Enum type index */ herr_t ret = 0; /* Generic return value */ @@ -7691,19 +7694,19 @@ test_versionbounds(void) ret = H5Tenum_insert(enum_type, "RED", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_GREEN; ret = H5Tenum_insert(enum_type, "GREEN", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_BLUE; ret = H5Tenum_insert(enum_type, "BLUE", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_ORANGE; ret = H5Tenum_insert(enum_type, "ORANGE", &enum_val); if (ret < 0) TEST_ERROR - H5_INC_ENUM(color_t, enum_val); + enum_val = E1_YELLOW; ret = H5Tenum_insert(enum_type, "YELLOW", &enum_val); if (ret < 0) TEST_ERROR @@ -7727,8 +7730,9 @@ test_versionbounds(void) skipping invalid combinations */ /* Create the file, create and write to a dataset with compound datatype */ /* Verify the dataset's datatype and its members */ - for(low = H5F_LIBVER_EARLIEST; low < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, low)) { - for(high = H5F_LIBVER_EARLIEST; high < H5F_LIBVER_NBOUNDS; H5_INC_ENUM(H5F_libver_t, high)) { + for(i = 0, low = versions[i]; i < versions_count; i++) { + + for(j = 0, high = versions[j]; j < versions_count; j++) { /* Set version bounds */ H5E_BEGIN_TRY { -- cgit v0.12