diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2002-06-11 16:03:04 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2002-06-11 16:03:04 (GMT) |
commit | 33a1bc03c43c68a95b301d8315a15fa7775851e4 (patch) | |
tree | 0402f78abb06b3d8e7b728ebb0a2f64bdff64fb6 /src/H5T.c | |
parent | e4a300b04e0eb4f3c7cfb96b925d5cf9975c8188 (diff) | |
download | hdf5-33a1bc03c43c68a95b301d8315a15fa7775851e4.zip hdf5-33a1bc03c43c68a95b301d8315a15fa7775851e4.tar.gz hdf5-33a1bc03c43c68a95b301d8315a15fa7775851e4.tar.bz2 |
[svn-r5586] Purpose:
Bug Fix
Description:
H5Dcreate and H5Tcommit allow "empty" compound and enumerated types (i.e.
ones with no members) to be stored in the file, but this causes an assertion
failure and is somewhat vapid.
Solution:
Check the datatype "makes sense" before using it for H5Dcreate and
H5Tcommit.
Platforms tested:
FreeBSD 4.5 (sleipnir)
Diffstat (limited to 'src/H5T.c')
-rw-r--r-- | src/H5T.c | 64 |
1 files changed, 61 insertions, 3 deletions
@@ -5851,14 +5851,15 @@ H5T_commit (H5G_entry_t *loc, const char *name, H5T_t *type) FUNC_ENTER_NOAPI(H5T_commit, FAIL); + assert (loc); + assert (name && *name); + assert (type); + /* * Check arguments. We cannot commit an immutable type because H5Tclose() * normally fails on such types (try H5Tclose(H5T_NATIVE_INT)) but closing * a named type should always succeed. */ - assert (loc); - assert (name && *name); - assert (type); if (H5T_STATE_NAMED==type->state || H5T_STATE_OPEN==type->state) { HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "data type is already committed"); @@ -5868,6 +5869,10 @@ H5T_commit (H5G_entry_t *loc, const char *name, H5T_t *type) "data type is immutable"); } + /* Check for a "sensible" datatype to store on disk */ + if(H5T_is_sensible(type)!=TRUE) + HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "datatype is not sensible"); + /* Find the insertion file */ if (NULL==(file=H5G_insertion_file(loc, name))) { HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, @@ -8089,6 +8094,59 @@ H5Tget_array_dims(hid_t type_id, hsize_t dims[], int perm[]) /*------------------------------------------------------------------------- + * Function: H5T_is_sensible + * + * Purpose: Determines if a data type is sensible to store on disk + * (i.e. not partially initialized) + * + * Return: Success: TRUE, FALSE + * + * Failure: Negative + * + * Programmer: Quincey Koziol + * Tuesday, June 11, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +htri_t +H5T_is_sensible(const H5T_t *dt) +{ + htri_t ret_value = FAIL; + + FUNC_ENTER_NOAPI(H5T_is_sensible, FAIL); + + assert(dt); + + switch(dt->type) { + case H5T_COMPOUND: + /* Only allow compound datatypes with at least one member to be stored on disk */ + if(dt->u.compnd.nmembs > 0) + ret_value=TRUE; + else + ret_value=FALSE; + break; + + case H5T_ENUM: + /* Only allow enum datatypes with at least one member to be stored on disk */ + if(dt->u.enumer.nmembs > 0) + ret_value=TRUE; + else + ret_value=FALSE; + break; + + default: + /* Assume all other datatype are sensible to store on disk */ + ret_value=TRUE; + break; + } /* end switch */ + + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- * Function: H5T_print_stats * * Purpose: Print statistics about a conversion path. Statistics are |