summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2009-10-27 21:29:54 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2009-10-27 21:29:54 (GMT)
commit3df83b192dbac78e5cb90a8933c24476cbc4b214 (patch)
tree4c760101eaead171d75a6f165530068bff2bad04
parent34c8292e76d33024e11e74c864a410b321f5dd5a (diff)
downloadhdf5-3df83b192dbac78e5cb90a8933c24476cbc4b214.zip
hdf5-3df83b192dbac78e5cb90a8933c24476cbc4b214.tar.gz
hdf5-3df83b192dbac78e5cb90a8933c24476cbc4b214.tar.bz2
[svn-r17755] Purpose: Fix assertion failure caused by H5Tcommit1/2
Description: Calling H5Tcommit_anon on a file with read only access would cause an assertion failure. Added a check to H5T_commit to return a failure in this case. Removed redundant check in H5T_commit_named. Tested: Fedora 11 (very minor change)
-rw-r--r--src/H5Tcommit.c8
-rw-r--r--test/dtypes.c11
2 files changed, 15 insertions, 4 deletions
diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c
index ebdf283..dea6bed 100644
--- a/src/H5Tcommit.c
+++ b/src/H5Tcommit.c
@@ -199,10 +199,6 @@ 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;
@@ -338,6 +334,10 @@ H5T_commit(H5F_t *file, H5T_t *type, hid_t tcpl_id, hid_t dxpl_id)
HDassert(type);
HDassert(tcpl_id != H5P_DEFAULT);
+ /* Check if we are allowed to write to this file */
+ if(0 == (H5F_INTENT(file) & H5F_ACC_RDWR))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "no write intent on file")
+
/*
* Check arguments. We cannot commit an immutable type because H5Tclose()
* normally fails on such types (try H5Tclose(H5T_NATIVE_INT)) but closing
diff --git a/test/dtypes.c b/test/dtypes.c
index 51f8f6d..2619f1b 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -3727,6 +3727,17 @@ test_named (hid_t fapl)
goto error;
}
+ /* Verify that H5Tcommit_anon returns an error */
+ if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
+ H5E_BEGIN_TRY {
+ status = H5Tcommit_anon(file, type, 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;