From 34c8292e76d33024e11e74c864a410b321f5dd5a Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Tue, 27 Oct 2009 15:56:54 -0500 Subject: [svn-r17751] Purpose: Fix assertion failure caused by H5Tcommit1/2 Description: Calling H5Tcommit1 or H5Tcommit2 on a file with read only access would cause an assertion failure. Added a check to H5T_commit_named to return a failure in this case. Also a minor fix in the link_filters test. Tested: Fedora 11 (very minor change) --- src/H5Tcommit.c | 4 ++++ test/dtypes.c | 43 +++++++++++++++++++++++++++++++++++++++++-- test/links.c | 4 ++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index f580c15..ebdf283 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -199,6 +199,10 @@ H5T_commit_named(const H5G_loc_t *loc, const char *name, H5T_t *dt, HDassert(tapl_id != H5P_DEFAULT); HDassert(dxpl_id != H5P_DEFAULT); + /* Check if we are allowed to write to this file */ + if(0 == (H5F_INTENT(loc->oloc->file) & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "no write intent on file") + /* Record the type's state so that we can revert to it if linking fails */ old_state = dt->shared->state; diff --git a/test/dtypes.c b/test/dtypes.c index 545a098..51f8f6d 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -3707,10 +3707,30 @@ test_named (hid_t fapl) if(H5Tclose(t3) < 0) goto error; if(H5Dclose(dset) < 0) goto error; - /* Clean up */ + /* Close */ if(H5Tclose(type) < 0) goto error; if(H5Sclose(space) < 0) goto error; if(H5Fclose(file) < 0) goto error; + + /* Reopen file with read only access */ + if ((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) + goto error; + + /* Verify that H5Tcommit2 returns an error */ + if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error; + H5E_BEGIN_TRY { + status = H5Tcommit2(file, "test_named_3 (should not exist)", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + } H5E_END_TRY; + if(status >= 0) { + H5_FAILED(); + HDputs (" Types should not be committable to a read-only file!"); + goto error; + } + + /* Close */ + if(H5Tclose(type) < 0) goto error; + if(H5Fclose(file) < 0) goto error; + PASSED(); return 0; @@ -6242,10 +6262,29 @@ test_deprec(hid_t fapl) if(!status) FAIL_PUTS_ERROR(" Opened named types should be named types!") - /* Clean up */ + /* Close */ if(H5Tclose(type) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR + /* Reopen file with read only access */ + if ((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) + goto error; + + /* Verify that H5Tcommit2 returns an error */ + if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error; + H5E_BEGIN_TRY { + status = H5Tcommit1(file, "test_named_3 (should not exist)", type); + } H5E_END_TRY; + if(status >= 0) { + H5_FAILED(); + HDputs (" Types should not be committable to a read-only file!"); + goto error; + } + + /* Close */ + if(H5Tclose(type) < 0) goto error; + if(H5Fclose(file) < 0) goto error; + PASSED(); return 0; diff --git a/test/links.c b/test/links.c index 8ee16a6..3cc7a36 100644 --- a/test/links.c +++ b/test/links.c @@ -8754,8 +8754,8 @@ link_filters(hid_t fapl, hbool_t new_format) || filter_config_out != (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) TEST_ERROR - if(H5Pget_filter2(gcpl2, 2, &flags_out, &cd_nelmts, &cd_value_out, (size_t)24, - name_out, &filter_config_out) < 0) + if(H5Pget_filter2(gcpl2, nfilters - 1, &flags_out, &cd_nelmts, + &cd_value_out, (size_t)24, name_out, &filter_config_out) < 0) TEST_ERROR if(flags_out != 0 || cd_value_out != cd_value || HDstrcmp(filter_class.name, name_out) -- cgit v0.12