summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorElena Pourmal <epourmal@hdfgroup.org>2002-06-11 19:31:19 (GMT)
committerElena Pourmal <epourmal@hdfgroup.org>2002-06-11 19:31:19 (GMT)
commitbd3d277cd78f8f987acebbef746947f23825a914 (patch)
tree8945f7c4c19ffae7dba9667dad774bf8e372ce62 /src
parent9075854dd9c97a5ab0775e3b65cdd3c4e9fdc543 (diff)
downloadhdf5-bd3d277cd78f8f987acebbef746947f23825a914.zip
hdf5-bd3d277cd78f8f987acebbef746947f23825a914.tar.gz
hdf5-bd3d277cd78f8f987acebbef746947f23825a914.tar.bz2
[svn-r5595]
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.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 1e886fc..edb5aaa 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -6916,6 +6916,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) {
@@ -6929,9 +6933,10 @@ 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 */
@@ -6973,7 +6978,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_NOAPI(H5T_enum_nameof, FAIL);
+ FUNC_ENTER_NOAPI(H5T_enum_valueof, FAIL);
/* Check args */
assert(dt && H5T_ENUM==dt->type);
@@ -6984,6 +6989,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) {
@@ -6997,9 +7006,10 @@ H5T_enum_valueof(H5T_t *dt, const char *name, void *value/*out*/)
break;
}
}
- if (md<0) {
- HRETURN_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL,
- "string 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, FAIL,
+ "string doesn't exist in the enumeration type");
}
HDmemcpy(value, dt->u.enumer.value+md*dt->size, dt->size);