diff options
author | Elena Pourmal <epourmal@hdfgroup.org> | 2002-06-11 19:22:52 (GMT) |
---|---|---|
committer | Elena Pourmal <epourmal@hdfgroup.org> | 2002-06-11 19:22:52 (GMT) |
commit | f19971bb05462c45b442181a6a282c21fcc1041f (patch) | |
tree | 85df6a58c759b432afdd75ae6bcfe543960c01a7 /src | |
parent | 3ed68f69fe422141dc69ad293654431abf8c4294 (diff) | |
download | hdf5-f19971bb05462c45b442181a6a282c21fcc1041f.zip hdf5-f19971bb05462c45b442181a6a282c21fcc1041f.tar.gz hdf5-f19971bb05462c45b442181a6a282c21fcc1041f.tar.bz2 |
[svn-r5593]
Purpose:
Bug #774 fix
Description:
H5Tenum_valueof and H5Tenum_nameof functions did not fail
when non-existing name or non-existing value were supplied.
This happened because binary search algorithm did not check
if value or name found during the search were equal to the supplied
one.
Solution:
Added an appropriate check condition.
Platforms tested:
Solaris 2.7 and Linux 2.2.18
Diffstat (limited to 'src')
-rw-r--r-- | src/H5T.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -6362,6 +6362,10 @@ H5T_enum_nameof(H5T_t *dt, void *value, char *name/*out*/, size_t size) H5T_sort_value(dt, NULL); lt = 0; rt = dt->u.enumer.nmembs; + if (rt == 0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, + "datatype has no members"); + } md = -1; while (lt<rt) { @@ -6375,11 +6379,13 @@ H5T_enum_nameof(H5T_t *dt, void *value, char *name/*out*/, size_t size) break; } } - if (md<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, - "value is not in the domain of the enumeration type"); + /* Value was not yet defined. This fixes bug # 774, 2002/06/05 EIP */ + if (cmp!=0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, + "value is currently not defined"); } + /* Save result name */ if (!name && NULL==(name=H5MM_malloc(strlen(dt->u.enumer.name[md])+1))) { HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, @@ -6419,7 +6425,7 @@ H5T_enum_valueof(H5T_t *dt, const char *name, void *value/*out*/) int lt, md, rt; /*indices for binary search */ int cmp; /*comparison result */ - FUNC_ENTER(H5T_enum_nameof, FAIL); + FUNC_ENTER(H5T_enum_valueof, FAIL); /* Check args */ assert(dt && H5T_ENUM==dt->type); @@ -6430,6 +6436,10 @@ H5T_enum_valueof(H5T_t *dt, const char *name, void *value/*out*/) H5T_sort_name(dt, NULL); lt = 0; rt = dt->u.enumer.nmembs; + if (rt == 0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, + "datatype has no members"); + } md = -1; while (lt<rt) { @@ -6443,11 +6453,12 @@ H5T_enum_valueof(H5T_t *dt, const char *name, void *value/*out*/) break; } } - if (md<0) { + if (cmp!=0) { HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, - "string is not in the domain of the enumeration type"); + "string doesn't exist in the enumeration type"); } + HDmemcpy(value, dt->u.enumer.value+md*dt->size, dt->size); FUNC_LEAVE(SUCCEED); } |