summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2011-04-17 19:16:38 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2011-04-17 19:16:38 (GMT)
commit0badac6423ddfeb881345838e3879ad413e52ad1 (patch)
tree0ad085535930a65392a00ee911579574d24008a0 /src
parenta99c68f3f9ac16df25d68a06947d92fcd0da220c (diff)
downloadhdf5-0badac6423ddfeb881345838e3879ad413e52ad1.zip
hdf5-0badac6423ddfeb881345838e3879ad413e52ad1.tar.gz
hdf5-0badac6423ddfeb881345838e3879ad413e52ad1.tar.bz2
[svn-r20537] Description:
Bring r20535 & r20536 from trunk to 1.8 branch: Add explicit test that checks that the 'fileno' field in H5O_info_t is the same for objects in the same file, whether the file was opened twice or not. Clean up various warnings & code formatting issues. Bring changes from Coverity branch to trunk: r20085: Purpose: Fix coverity issue 793 Description: Modified H5S_hyper_project_simple_higher() to free the entire span list in new_space on failure. r20091: This is a fix for coverity bug #1683. Changed the two printfs to use %lu (unsigned long) for printing "dset_size". r20162: Purpose: Fix coverity issue 785 Description: Modified H5T_enum_nameof() to free "name" on failure if it was allocated. Also clarified some code in H5S_hyper_rebuild_helper(). r20189: Addressed coverity defect 783. H5SL_new_node() in H5SL.c was failing to free space allocated in its first alloc if the second alloc failed. Added a call to H5FL_FREE to address this issue. This is purely to keep coverity happy -- if this code is ever triggered, we have much larger problems. Note that this fix will trigger an unused return value complaint from coverity next week. r20190: Fixed Coverity issues 1561 1565 and 1678 (UNUSED_VALUES) by moving checks of return values to after the function call. r20191: Fixed coverity issues 643 644 and 1678 (CHECKED_RETURN). r20232: Addressed coverity issues 923-925. Replaced calls to sprintf with calls to HDsnprintf. r20233: Fix coverity issue 662. Don't try to sort 0 attributes in H5Aint.c. r20234: Fix coverity issue 664. Check for NULL before dereferencing in H5Gdeprec.c. r20271: Purpose: Fix coverity issue 784 Description: Modified H5_debug_mask() to keep a list of files opened for use as a debugging output stream, and modified H5_term_library to close these files on exit. r20272: addressed coverity issues 838 & 955. Issue was use of strcpy() -- existing code was safe, but modified to use strncpy() to keep coverity happy. r20273: Addresed coverity issues 1388 and 1389. Initialized sel_iter->type to NULL in H5S_select_iter_init. r20275: Purpose: Fix valgrind issue in mf.c Description: Fixed bug (incomplete if statement) in test_mf_fs_alloc_free() so the retrieved node gets freed. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, w/threadsafe, in production mode Linux/PPC 2.6 (heiwa) w/C++ & FORTRAN, w/threadsafe, in debug mode
Diffstat (limited to 'src')
-rw-r--r--src/H5.c29
-rw-r--r--src/H5Aint.c9
-rw-r--r--src/H5B2dbg.c10
-rw-r--r--src/H5Gdeprec.c7
-rw-r--r--src/H5Gtraverse.c2
-rw-r--r--src/H5I.c2
-rw-r--r--src/H5P.c2
-rw-r--r--src/H5Pint.c2
-rwxr-xr-xsrc/H5Pocpl.c8
-rw-r--r--src/H5RS.c8
-rw-r--r--src/H5SL.c4
-rw-r--r--src/H5Shyper.c21
-rw-r--r--src/H5Sselect.c11
-rw-r--r--src/H5Tenum.c84
-rw-r--r--src/H5private.h6
15 files changed, 129 insertions, 76 deletions
diff --git a/src/H5.c b/src/H5.c
index 045c65b..b6ad4e4 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -27,6 +27,7 @@
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free lists */
#include "H5Lprivate.h" /* Links */
+#include "H5MMprivate.h" /* Memory management */
#include "H5Pprivate.h" /* Property lists */
#include "H5Tprivate.h" /* Datatypes */
#include "H5SLprivate.h" /* Skip lists */
@@ -309,6 +310,16 @@ H5_term_library(void)
} /* end if */
#endif
+ /* Free open debugging streams */
+ while(H5_debug_g.open_stream) {
+ H5_debug_open_stream_t *tmp_open_stream;
+
+ tmp_open_stream = H5_debug_g.open_stream;
+ (void)HDfclose(H5_debug_g.open_stream->stream);
+ H5_debug_g.open_stream = H5_debug_g.open_stream->next;
+ (void)H5MM_free(tmp_open_stream);
+ } /* end while */
+
/* Mark library as closed */
H5_INIT_GLOBAL = FALSE;
done:
@@ -532,9 +543,21 @@ H5_debug_mask(const char *s)
}
} else if (HDisdigit(*s)) {
- int fd = (int)HDstrtol (s, &rest, 0);
- if ((stream=HDfdopen(fd, "w"))!=NULL)
- (void)HDsetvbuf (stream, NULL, _IOLBF, (size_t)0);
+ int fd = (int)HDstrtol(s, &rest, 0);
+ H5_debug_open_stream_t *open_stream;
+
+ if((stream = HDfdopen(fd, "w")) != NULL) {
+ (void)HDsetvbuf(stream, NULL, _IOLBF, (size_t)0);
+
+ if(NULL == (open_stream = (H5_debug_open_stream_t *)H5MM_malloc(sizeof(H5_debug_open_stream_t)))) {
+ (void)HDfclose(stream);
+ return;
+ } /* end if */
+
+ open_stream->stream = stream;
+ open_stream->next = H5_debug_g.open_stream;
+ H5_debug_g.open_stream = open_stream;
+ } /* end if */
s = rest;
} else {
s++;
diff --git a/src/H5Aint.c b/src/H5Aint.c
index 10b7257..f1a40bd 100644
--- a/src/H5Aint.c
+++ b/src/H5Aint.c
@@ -232,9 +232,12 @@ H5A_compact_build_table(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5_index_t idx_type,
/* Correct # of attributes in table */
atable->nattrs = udata.curr_attr;
- /* Sort attribute table in correct iteration order */
- if(H5A_attr_sort_table(atable, idx_type, order) < 0)
- HGOTO_ERROR(H5E_ATTR, H5E_CANTSORT, FAIL, "error sorting attribute table")
+ /* Don't sort an empty table. */
+ if(atable->nattrs > 0) {
+ /* Sort attribute table in correct iteration order */
+ if(H5A_attr_sort_table(atable, idx_type, order) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTSORT, FAIL, "error sorting attribute table")
+ } /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5B2dbg.c b/src/H5B2dbg.c
index a7f6819..5a0b341 100644
--- a/src/H5B2dbg.c
+++ b/src/H5B2dbg.c
@@ -169,7 +169,7 @@ H5B2_hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
/* Print relevant node info */
HDfprintf(stream, "%*sNode Info: (max_nrec/split_nrec/merge_nrec)\n", indent, "");
for(u = 0; u < (unsigned)(hdr->depth + 1); u++) {
- sprintf(temp_str, "Depth %u:", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Depth %u:", u);
HDfprintf(stream, "%*s%-*s (%u/%u/%u)\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str,
hdr->node_info[u].max_nrec, hdr->node_info[u].split_nrec, hdr->node_info[u].merge_nrec);
@@ -281,7 +281,7 @@ H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
/* Print all node pointers and records */
for(u = 0; u < internal->nrec; u++) {
/* Print node pointer */
- sprintf(temp_str, "Node pointer #%u: (all/node/addr)", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Node pointer #%u: (all/node/addr)", u);
HDfprintf(stream, "%*s%-*s (%Hu/%u/%a)\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str,
internal->node_ptrs[u].all_nrec,
@@ -289,7 +289,7 @@ H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
internal->node_ptrs[u].addr);
/* Print record */
- sprintf(temp_str, "Record #%u:", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Record #%u:", u);
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str);
HDassert(H5B2_INT_NREC(internal, hdr, u));
@@ -298,7 +298,7 @@ H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
} /* end for */
/* Print final node pointer */
- sprintf(temp_str, "Node pointer #%u: (all/node/addr)", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Node pointer #%u: (all/node/addr)", u);
HDfprintf(stream, "%*s%-*s (%Hu/%u/%a)\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str,
internal->node_ptrs[u].all_nrec,
@@ -410,7 +410,7 @@ H5B2_leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
/* Print all node pointers and records */
for(u = 0; u < leaf->nrec; u++) {
/* Print record */
- sprintf(temp_str, "Record #%u:", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Record #%u:", u);
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str);
HDassert(H5B2_LEAF_NREC(leaf, hdr, u));
diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c
index d76159e..9a0c1a2 100644
--- a/src/H5Gdeprec.c
+++ b/src/H5Gdeprec.c
@@ -893,7 +893,7 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5G_get_objinfo_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t *lnk,
+H5G_get_objinfo_cb(H5G_loc_t UNUSED *grp_loc/*in*/, const char *name, const H5O_link_t *lnk,
H5G_loc_t *obj_loc, void *_udata/*in,out*/, H5G_own_loc_t *own_loc/*out*/)
{
H5G_trav_goi_t *udata = (H5G_trav_goi_t *)_udata; /* User data passed in */
@@ -902,7 +902,7 @@ H5G_get_objinfo_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t
FUNC_ENTER_NOAPI_NOINIT(H5G_get_objinfo_cb)
/* Check if the name in this group resolved to a valid link */
- if(lnk == NULL && obj_loc == NULL)
+ if(lnk == NULL || obj_loc == NULL)
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "'%s' doesn't exist", name)
/* Only modify user's buffer if it's available */
@@ -910,8 +910,7 @@ H5G_get_objinfo_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t
H5G_stat_t *statbuf = udata->statbuf; /* Convenience pointer for statbuf */
/* Common code to retrieve the file's fileno */
- /* (Use the object location's file info, if it's available) */
- if(H5F_get_fileno((obj_loc ? obj_loc : grp_loc)->oloc->file, &statbuf->fileno[0]) < 0)
+ if(H5F_get_fileno(obj_loc->oloc->file, &statbuf->fileno[0]) < 0)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "unable to read fileno")
/* Info for soft and UD links is gotten by H5L_get_info. If we have
diff --git a/src/H5Gtraverse.c b/src/H5Gtraverse.c
index 3d82b6f..9519f32 100644
--- a/src/H5Gtraverse.c
+++ b/src/H5Gtraverse.c
@@ -604,7 +604,7 @@ H5G_traverse_real(const H5G_loc_t *_loc, const char *name, unsigned target,
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "can't wrap buffer")
/* Get a pointer to a buffer that's large enough */
- if(NULL == (comp = (uint8_t *)H5WB_actual(wb, (HDstrlen(name) + 1))))
+ if(NULL == (comp = (char *)H5WB_actual(wb, (HDstrlen(name) + 1))))
HGOTO_ERROR(H5E_SYM, H5E_NOSPACE, FAIL, "can't get actual buffer")
/* Traverse the path */
diff --git a/src/H5I.c b/src/H5I.c
index 6fb13d2..79a53f0 100644
--- a/src/H5I.c
+++ b/src/H5I.c
@@ -935,7 +935,7 @@ done:
*
* Purpose: Substitute a new object pointer for the specified ID.
*
- * Return: Success: Non-null previsou object pointer associated
+ * Return: Success: Non-null previous object pointer associated
* with the specified ID.
* Failure: NULL
*
diff --git a/src/H5P.c b/src/H5P.c
index 3b4215b..afcb84e 100644
--- a/src/H5P.c
+++ b/src/H5P.c
@@ -468,7 +468,7 @@ H5Pregister2(hid_t cls_id, const char *name, size_t size, void *def_value,
HDassert(old_pclass == orig_pclass);
/* Close the previous class */
- if(H5P_close_class(orig_pclass) < 0)
+ if(H5P_close_class(old_pclass) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "unable to close original property class after substitution")
} /* end if */
diff --git a/src/H5Pint.c b/src/H5Pint.c
index 67bb101..4ae274e 100644
--- a/src/H5Pint.c
+++ b/src/H5Pint.c
@@ -4188,7 +4188,7 @@ H5P_copy_prop_pclass(hid_t dst_id, hid_t src_id, const char *name)
HDassert(old_dst_pclass == orig_dst_pclass);
/* Close the previous class */
- if(H5P_close_class(orig_dst_pclass) < 0)
+ if(H5P_close_class(old_dst_pclass) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTCLOSEOBJ, FAIL, "unable to close original property class after substitution")
} /* end if */
diff --git a/src/H5Pocpl.c b/src/H5Pocpl.c
index ac46228..dec2cfe 100755
--- a/src/H5Pocpl.c
+++ b/src/H5Pocpl.c
@@ -1025,14 +1025,6 @@ H5Pget_filter_by_id2(hid_t plist_id, H5Z_filter_t id, unsigned int *flags/*out*/
if(NULL == (plist = H5P_object_verify(plist_id, H5P_OBJECT_CREATE)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
- /* Get the pipeline property to query */
- if(H5P_get(plist, H5O_CRT_PIPELINE_NAME, &pline) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get pipeline")
-
- /* Get pointer to filter in pipeline */
- if(NULL == (filter = H5Z_filter_info(&pline, id)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "filter ID is invalid")
-
/* Get filter information */
if(H5P_get_filter_by_id(plist, id, flags, cd_nelmts, cd_values, namelen,
name, filter_config) < 0)
diff --git a/src/H5RS.c b/src/H5RS.c
index 0a3f134..06fc81e 100644
--- a/src/H5RS.c
+++ b/src/H5RS.c
@@ -66,9 +66,11 @@ H5RS_xstrdup(const char *s)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5RS_xstrdup)
if(s) {
- ret_value = (char *)H5FL_BLK_MALLOC(str_buf, HDstrlen(s) + 1);
+ size_t len = HDstrlen(s) + 1;
+
+ ret_value = (char *)H5FL_BLK_MALLOC(str_buf, len);
HDassert(ret_value);
- HDstrcpy(ret_value, s);
+ HDstrncpy(ret_value, s, len);
} /* end if */
else
ret_value = NULL;
@@ -352,7 +354,7 @@ H5RS_dup_str(const char *s)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Copy name for full path */
- HDstrcpy(new_str, s);
+ HDstrncpy(new_str, s, (path_len + 1));
/* Create reference counted string for path */
ret_value = H5RS_own(new_str);
diff --git a/src/H5SL.c b/src/H5SL.c
index c3788b4..c996392 100644
--- a/src/H5SL.c
+++ b/src/H5SL.c
@@ -583,8 +583,10 @@ H5SL_new_node(void *item, const void *key, uint32_t hashval)
ret_value->item = item;
ret_value->level = 0;
ret_value->hashval = hashval;
- if(NULL == (ret_value->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0])))
+ if(NULL == (ret_value->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0]))) {
+ ret_value = H5FL_FREE(H5SL_node_t, ret_value);
HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")
+ } /* end if */
ret_value->log_nalloc = 0;
done:
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index 4aa887b..2622101 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -4191,16 +4191,24 @@ H5S_hyper_project_simple_higher(const H5S_t *base_space, H5S_t *new_space)
H5S_hyper_span_t *new_span; /* Temporary hyperslab span */
/* Allocate a new span_info node */
- if(NULL == (new_span_info = H5FL_MALLOC(H5S_hyper_span_info_t)))
+ if(NULL == (new_span_info = H5FL_MALLOC(H5S_hyper_span_info_t))) {
+ if(prev_span)
+ if(H5S_hyper_free_span(prev_span) < 0)
+ HERROR(H5E_DATASPACE, H5E_CANTFREE, "can't free hyperslab span");
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span info")
+ } /* end if */
/* Check for linking into higher span */
if(prev_span)
prev_span->down = new_span_info;
/* Allocate a new node */
- if(NULL == (new_span = H5S_hyper_new_span(0, 0, NULL, NULL)))
+ if(NULL == (new_span = H5S_hyper_new_span(0, 0, NULL, NULL))) {
+ HDassert(new_span_info);
+ if(!prev_span)
+ (void)H5FL_FREE(H5S_hyper_span_info_t, new_span_info);
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span")
+ } /* end if */
/* Set the span_info information */
new_span_info->count = 1;
@@ -4225,6 +4233,15 @@ H5S_hyper_project_simple_higher(const H5S_t *base_space, H5S_t *new_space)
prev_span->down->count++;
done:
+ if(ret_value < 0 && new_space->select.sel_info.hslab->span_lst) {
+ if(new_space->select.sel_info.hslab->span_lst->head)
+ if(H5S_hyper_free_span(
+ new_space->select.sel_info.hslab->span_lst->head) < 0)
+ HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't free hyperslab span")
+
+ new_space->select.sel_info.hslab->span_lst = H5FL_FREE(H5S_hyper_span_info_t, new_space->select.sel_info.hslab->span_lst);
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_hyper_project_simple_higher() */
diff --git a/src/H5Sselect.c b/src/H5Sselect.c
index 2a0e63f..db18780 100644
--- a/src/H5Sselect.c
+++ b/src/H5Sselect.c
@@ -874,13 +874,13 @@ H5S_select_iter_init(H5S_sel_iter_t *sel_iter, const H5S_t *space, size_t elmt_s
FUNC_ENTER_NOAPI_NOFUNC(H5S_select_iter_init)
/* Check args */
- assert(sel_iter);
- assert(space);
+ HDassert(sel_iter);
+ HDassert(space);
/* Initialize common information */
/* Save the dataspace's rank */
- sel_iter->rank=space->extent.rank;
+ sel_iter->rank = space->extent.rank;
/* Point to the dataspace dimensions, if there are any */
if(sel_iter->rank > 0)
@@ -889,10 +889,11 @@ H5S_select_iter_init(H5S_sel_iter_t *sel_iter, const H5S_t *space, size_t elmt_s
sel_iter->dims = NULL;
/* Save the element size */
- sel_iter->elmt_size=elmt_size;
+ sel_iter->elmt_size = elmt_size;
/* Call initialization routine for selection type */
- ret_value= (*space->select.type->iter_init)(sel_iter, space);
+ ret_value = (*space->select.type->iter_init)(sel_iter, space);
+ HDassert(sel_iter->type);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_select_iter_init() */
diff --git a/src/H5Tenum.c b/src/H5Tenum.c
index ec3f2e1..8ef88f5 100644
--- a/src/H5Tenum.c
+++ b/src/H5Tenum.c
@@ -415,65 +415,73 @@ done:
static char *
H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/, size_t size)
{
- unsigned lt, md=0, rt; /*indices for binary search */
- int cmp=(-1); /*comparison result */
- H5T_t *copied_dt = NULL; /*do sorting in copied datatype */
- char *ret_value; /* Return value */
+ H5T_t *copied_dt = NULL; /* Do sorting in copied datatype */
+ unsigned lt, md = 0, rt; /* Indices for binary search */
+ int cmp = (-1); /* Comparison result */
+ hbool_t alloc_name = FALSE; /* Whether name has been allocated */
+ char *ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5T_enum_nameof, NULL)
+ FUNC_ENTER_NOAPI_NOINIT(H5T_enum_nameof)
/* Check args */
- assert(dt && H5T_ENUM==dt->shared->type);
- assert(value);
- assert(name || 0==size);
- if (name && size>0) *name = '\0';
+ HDassert(dt && H5T_ENUM == dt->shared->type);
+ HDassert(value);
+ HDassert(name || 0 == size);
+
+ if(name && size > 0)
+ *name = '\0';
/* Sanity check */
- if (dt->shared->u.enumer.nmembs == 0)
+ if(dt->shared->u.enumer.nmembs == 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "datatype has no members")
/* Do a binary search over the values to find the correct one. Do sorting
* and search on the copied datatype to protect the original order. */
- if (NULL==(copied_dt=H5T_copy(dt, H5T_COPY_ALL)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type");
- if(H5T_sort_value(copied_dt, NULL)<0)
- HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOMPARE, NULL, "value sort failed")
+ if(NULL == (copied_dt = H5T_copy(dt, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type")
+ if(H5T_sort_value(copied_dt, NULL) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOMPARE, NULL, "value sort failed")
lt = 0;
rt = copied_dt->shared->u.enumer.nmembs;
-
- while (lt<rt) {
- md = (lt+rt)/2;
- cmp = HDmemcmp(value, copied_dt->shared->u.enumer.value+md*copied_dt->shared->size, copied_dt->shared->size);
- if (cmp<0) {
+ while(lt < rt) {
+ md = (lt + rt) / 2;
+ cmp = HDmemcmp(value, copied_dt->shared->u.enumer.value + md * copied_dt->shared->size, copied_dt->shared->size);
+ if(cmp < 0)
rt = md;
- } else if (cmp>0) {
- lt = md+1;
- } else {
+ else if(cmp > 0)
+ lt = md + 1;
+ else
break;
- }
- }
+ } /* end while */
+
/* Value was not yet defined. This fixes bug # 774, 2002/06/05 EIP */
- if (cmp!=0)
+ if(cmp != 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "value is currently not defined")
/* Save result name */
- if(!name && NULL == (name = (char *)H5MM_malloc(HDstrlen(copied_dt->shared->u.enumer.name[md]) + 1)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ if(!name) {
+ if(NULL == (name = (char *)H5MM_malloc(
+ HDstrlen(copied_dt->shared->u.enumer.name[md]) + 1)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ alloc_name = TRUE;
+ } /* end if */
HDstrncpy(name, copied_dt->shared->u.enumer.name[md], size);
- if (HDstrlen(copied_dt->shared->u.enumer.name[md])>=size)
+ if(HDstrlen(copied_dt->shared->u.enumer.name[md]) >= size)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, NULL, "name has been truncated")
/* Set return value */
- ret_value=name;
+ ret_value = name;
done:
if(copied_dt)
if(H5T_close(copied_dt) < 0)
HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close data type");
+ if(!ret_value && alloc_name)
+ H5MM_free(name);
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5T_enum_nameof() */
/*-------------------------------------------------------------------------
@@ -501,8 +509,8 @@ done:
herr_t
H5Tenum_valueof(hid_t type, const char *name, void *value/*out*/)
{
- H5T_t *dt = NULL;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5T_t *dt;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(H5Tenum_valueof, FAIL)
H5TRACE3("e", "i*sx", type, name, value);
@@ -512,17 +520,17 @@ H5Tenum_valueof(hid_t type, const char *name, void *value/*out*/)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
if(H5T_ENUM != dt->shared->type)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
- if (!name || !*name)
+ if(!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
- if (!value)
+ if(!value)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value buffer")
- if (H5T_enum_valueof(dt, name, value)<0)
+ if(H5T_enum_valueof(dt, name, value) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "valueof query failed")
done:
FUNC_LEAVE_API(ret_value)
-}
+} /* H5Tenum_valueof() */
/*-------------------------------------------------------------------------
@@ -551,11 +559,11 @@ static herr_t
H5T_enum_valueof(const H5T_t *dt, const char *name, void *value/*out*/)
{
unsigned lt, md=0, rt; /*indices for binary search */
- int cmp=(-1); /*comparison result */
+ int cmp=(-1); /*comparison result */
H5T_t *copied_dt = NULL; /*do sorting in copied datatype */
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5T_enum_valueof, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5T_enum_valueof)
/* Check args */
assert(dt && H5T_ENUM==dt->shared->type);
diff --git a/src/H5private.h b/src/H5private.h
index d1862f9..b465ff6 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -1524,6 +1524,11 @@ typedef enum {
H5_NPKGS /*Must be last */
} H5_pkg_t;
+typedef struct H5_debug_open_stream_t {
+ FILE *stream; /* Open output stream */
+ struct H5_debug_open_stream_t *next; /* Next open output stream */
+} H5_debug_open_stream_t;
+
typedef struct H5_debug_t {
FILE *trace; /*API trace output stream */
hbool_t ttop; /*Show only top-level calls? */
@@ -1532,6 +1537,7 @@ typedef struct H5_debug_t {
const char *name; /*package name */
FILE *stream; /*output stream or NULL */
} pkg[H5_NPKGS];
+ H5_debug_open_stream_t *open_stream; /* Stack of open output streams */
} H5_debug_t;
extern H5_debug_t H5_debug_g;