diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2011-04-17 18:57:07 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2011-04-17 18:57:07 (GMT) |
commit | 9431c7a97e5f44b91d557b0e9693fc110a2578dc (patch) | |
tree | 23f4162b68d45daffee0466caaa4a888c449df04 | |
parent | 2898c115902975fa9e0cb4634a6b65598d24b445 (diff) | |
download | hdf5-9431c7a97e5f44b91d557b0e9693fc110a2578dc.zip hdf5-9431c7a97e5f44b91d557b0e9693fc110a2578dc.tar.gz hdf5-9431c7a97e5f44b91d557b0e9693fc110a2578dc.tar.bz2 |
[svn-r20536] Description:
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
-rw-r--r-- | src/H5.c | 29 | ||||
-rw-r--r-- | src/H5Aint.c | 9 | ||||
-rw-r--r-- | src/H5B2dbg.c | 10 | ||||
-rw-r--r-- | src/H5Gdeprec.c | 7 | ||||
-rw-r--r-- | src/H5Gtraverse.c | 2 | ||||
-rw-r--r-- | src/H5I.c | 2 | ||||
-rw-r--r-- | src/H5P.c | 2 | ||||
-rw-r--r-- | src/H5Pint.c | 2 | ||||
-rwxr-xr-x | src/H5Pocpl.c | 8 | ||||
-rw-r--r-- | src/H5RS.c | 8 | ||||
-rw-r--r-- | src/H5SL.c | 4 | ||||
-rw-r--r-- | src/H5Shyper.c | 21 | ||||
-rw-r--r-- | src/H5Sselect.c | 11 | ||||
-rw-r--r-- | src/H5Tenum.c | 84 | ||||
-rw-r--r-- | src/H5private.h | 6 | ||||
-rw-r--r-- | test/links.c | 46 | ||||
-rw-r--r-- | test/mf.c | 3 | ||||
-rw-r--r-- | test/tvlstr.c | 6 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 6 | ||||
-rw-r--r-- | tools/misc/talign.c | 35 |
20 files changed, 193 insertions, 108 deletions
@@ -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 */ @@ -313,6 +314,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: @@ -536,9 +547,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 a47ee14..4e610e4 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 c905722..8a45b8e 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 50a2894..4397d1c 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 */ @@ -888,7 +888,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 * @@ -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) @@ -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); @@ -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 9cebdaa..7950117 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1530,6 +1530,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? */ @@ -1538,6 +1543,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; diff --git a/test/links.c b/test/links.c index b892549..261adbc 100644 --- a/test/links.c +++ b/test/links.c @@ -1627,7 +1627,7 @@ test_deprec(hid_t fapl, hbool_t new_format) hid_t file_id = -1; hid_t group1_id = -1; hid_t group2_id = -1; - H5G_stat_t sb_hard1, sb_hard2, sb_soft1; + H5G_stat_t sb_hard1, sb_hard2, sb_soft1, sb_soft2; H5G_obj_t obj_type; /* Object type */ hsize_t num_objs; /* Number of objects in a group */ char filename[1024]; @@ -1656,6 +1656,7 @@ test_deprec(hid_t fapl, hbool_t new_format) if(H5Glink(file_id, H5G_LINK_HARD, "group2", "group1/link_to_group2") < 0) FAIL_STACK_ERROR if(H5Glink2(file_id, "group1", H5G_LINK_HARD, group2_id, "link_to_group1") < 0) FAIL_STACK_ERROR if(H5Glink2(file_id, "link_to_group1", H5G_LINK_SOFT, H5G_SAME_LOC, "group2/soft_link_to_group1") < 0) FAIL_STACK_ERROR + if(H5Glink2(file_id, "dangle", H5G_LINK_SOFT, H5G_SAME_LOC, "group2/dangle_soft_link") < 0) FAIL_STACK_ERROR /* Test getting the names for objects */ if(H5Gget_objname_by_idx(group1_id, (hsize_t)0, tmpstr, sizeof(tmpstr)) < 0) FAIL_STACK_ERROR @@ -1708,6 +1709,15 @@ test_deprec(hid_t fapl, hbool_t new_format) if(HDstrcmp("link_to_group1", tmpstr)) TEST_ERROR + /* Test the dangling soft link */ + if(H5Gget_objinfo(file_id, "/group2/dangle_soft_link", FALSE, &sb_soft2) < 0) FAIL_STACK_ERROR + if(sb_soft2.type != H5G_LINK) TEST_ERROR + if(sb_soft2.linklen != HDstrlen("dangle") + 1) TEST_ERROR + + if(H5Gget_linkval(group2_id, "dangle_soft_link", sb_soft2.linklen, tmpstr) < 0) FAIL_STACK_ERROR + if(HDstrcmp("dangle", tmpstr)) TEST_ERROR + + /* Test H5Gmove and H5Gmove2 */ if(H5Gmove(file_id, "group1", "moved_group1") < 0) FAIL_STACK_ERROR if(H5Gmove2(file_id, "group2", group1_id, "moved_group2") < 0) FAIL_STACK_ERROR @@ -3538,7 +3548,7 @@ external_set_elink_fapl1(hid_t fapl, hbool_t new_format) HDmemset(memb_addr, 0, sizeof memb_addr); HDmemset(sv, 0, sizeof sv); - for(mt = 0; mt < H5FD_MEM_NTYPES; mt++) { + for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) { memb_map[mt] = H5FD_MEM_SUPER; memb_fapl[mt] = H5P_DEFAULT; } /* end for */ @@ -9567,7 +9577,7 @@ link_filters(hid_t fapl, hbool_t new_format) /* Check that the file size is smaller with the filter */ if((double)filesize_filtered - > (filesize_unfiltered * FILTER_FILESIZE_MAX_FRACTION)) + > ((double)filesize_unfiltered * FILTER_FILESIZE_MAX_FRACTION)) TEST_ERROR /* Close */ @@ -11135,9 +11145,9 @@ delete_by_idx(hid_t fapl) herr_t ret; /* Generic return value */ /* Loop over operating on different indices on link fields */ - for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) { + for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) { /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_DEC; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_DEC; H5_INC_ENUM(H5_iter_order_t, order)) { /* Loop over using index for creation order value */ for(use_index = FALSE; use_index <= TRUE; use_index++) { /* Print appropriate test message */ @@ -11451,7 +11461,7 @@ delete_by_idx_old(hid_t fapl) herr_t ret; /* Generic return value */ /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_DEC; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_DEC; H5_INC_ENUM(H5_iter_order_t, order)) { /* Print test banner */ if(order == H5_ITER_INC) TESTING("deleting links by index in increasing order in old-style group") @@ -11974,9 +11984,9 @@ link_iterate(hid_t fapl) iter_info.visited = visited; /* Loop over operating on different indices on link fields */ - for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) { + for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) { /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Loop over using index for creation order value */ for(use_index = FALSE; use_index <= TRUE; use_index++) { /* Print appropriate test message */ @@ -12426,7 +12436,7 @@ link_iterate_old(hid_t fapl) iter_info.visited = visited; /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Print appropriate test message */ if(order == H5_ITER_INC) { TESTING("iterating over links by name index in increasing order in old-style group") @@ -12662,9 +12672,9 @@ open_by_idx(hid_t fapl) if((mount_file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR /* Loop over operating on different indices on link fields */ - for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) { + for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) { /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <= H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Loop over using index for creation order value */ for(use_index = FALSE; use_index <= TRUE; use_index++) { /* Print appropriate test message */ @@ -12878,7 +12888,7 @@ open_by_idx_old(hid_t fapl) if((mount_file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Print appropriate test message */ if(order == H5_ITER_INC) { TESTING("open object by name index in increasing order in old-style group") @@ -13098,9 +13108,9 @@ object_info(hid_t fapl) if((space_id = H5Screate(H5S_SCALAR)) < 0) TEST_ERROR /* Loop over operating on different indices on link fields */ - for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) { + for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) { /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Loop over using index for creation order value */ for(use_index = FALSE; use_index <= TRUE; use_index++) { /* Print appropriate test message */ @@ -13334,7 +13344,7 @@ object_info_old(hid_t fapl) if((space_id = H5Screate(H5S_SCALAR)) < 0) TEST_ERROR /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Print appropriate test message */ if(order == H5_ITER_INC) { TESTING("query object info by name index in increasing order in old-style group") @@ -13487,9 +13497,9 @@ group_info(hid_t fapl) if(H5Pget_link_phase_change(gcpl_id, &max_compact, &min_dense) < 0) TEST_ERROR /* Loop over operating on different indices on link fields */ - for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) { + for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) { /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { /* Loop over using index for creation order value */ for(use_index = FALSE; use_index <= TRUE; use_index++) { /* Print appropriate test message */ @@ -13898,7 +13908,7 @@ group_info_old(hid_t fapl) unsigned u, v; /* Local index variables */ /* Loop over operating in different orders */ - for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; order++) { + for(order = H5_ITER_INC; order <=H5_ITER_NATIVE; H5_INC_ENUM(H5_iter_order_t, order)) { if(order == H5_ITER_INC) { TESTING("query group info by name index in increasing order in old-style group") } /* end if */ @@ -1174,7 +1174,8 @@ test_mf_fs_alloc_free(hid_t fapl) /* Remove section A from free-space */ if(H5FS_sect_find(f, H5P_DATASET_XFER_DEFAULT, f->shared->fs_man[type], - (hsize_t)TEST_BLOCK_SIZE30, (H5FS_section_info_t **)&node) < 0) + (hsize_t)TEST_BLOCK_SIZE30, (H5FS_section_info_t **)&node) < 0) + TEST_ERROR /* Free the free-space section node */ if(H5MF_sect_simple_free((H5FS_section_info_t *)node) < 0) diff --git a/test/tvlstr.c b/test/tvlstr.c index 87008aa..02bd59d 100644 --- a/test/tvlstr.c +++ b/test/tvlstr.c @@ -388,6 +388,7 @@ static void test_vlstring_type(void) hid_t tid_vlstr; H5T_cset_t cset; H5T_str_t pad; + htri_t vl_str; /* Whether string is VL */ herr_t ret; /* Output message about test being performed */ @@ -417,6 +418,11 @@ static void test_vlstring_type(void) ret = H5Tis_variable_str(tid_vlstr); VERIFY(ret, TRUE, "H5Tis_variable_str"); + /* Verify that the class detects as a string */ + vl_str = H5Tdetect_class(tid_vlstr, H5T_STRING); + CHECK(vl_str, FAIL, "H5Tdetect_class"); + VERIFY(vl_str, TRUE, "H5Tdetect_class"); + /* Check default character set and padding */ cset = H5Tget_cset(tid_vlstr); VERIFY(cset, H5T_CSET_ASCII, "H5Tget_cset"); diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index 5048b87..b1df66e 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -786,9 +786,11 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_ */ if(link_info->linfo.type == H5L_TYPE_EXTERNAL) { fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_sec2(fapl); + if(H5Pset_fapl_sec2(fapl) < 0) + goto out; lapl = H5Pcreate(H5P_LINK_ACCESS); - H5Pset_elink_fapl(lapl, fapl); + if(H5Pset_elink_fapl(lapl, fapl) < 0) + goto out; } /* end if */ /* Check for retrieving object info */ diff --git a/tools/misc/talign.c b/tools/misc/talign.c index 24420bf..88ebaa6 100644 --- a/tools/misc/talign.c +++ b/tools/misc/talign.c @@ -50,10 +50,10 @@ int main(void) float fnok[2] = {5678., 6785.}; float *fptr; - char *data; - char *mname; + char *data = NULL; int result = 0; + herr_t error = 1; printf("%-70s", "Testing alignment in compound datatypes"); @@ -67,7 +67,7 @@ int main(void) } H5E_BEGIN_TRY { - H5Ldelete(fil, setname, H5P_DEFAULT); + (void)H5Ldelete(fil, setname, H5P_DEFAULT); } H5E_END_TRY; cs6 = H5Tcopy(H5T_C_S1); @@ -87,7 +87,7 @@ int main(void) H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt); H5Tclose(array_dt); - fix=h5tools_get_native_type(cmp); + fix = h5tools_get_native_type(cmp); cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok)); @@ -107,7 +107,8 @@ int main(void) H5Tclose(array_dt); plist = H5Pcreate(H5P_DATASET_XFER); - H5Pset_preserve(plist, 1); + if((error = H5Pset_preserve(plist, 1)) < 0) + goto out; /* * Create a small dataset, and write data into it we write each field @@ -136,25 +137,36 @@ int main(void) H5Dread(set, fix, spc, H5S_ALL, H5P_DEFAULT, data); fptr = (float *)(data + H5Tget_member_offset(fix, 1)); - if(fok[0] != fptr[0] || fok[1] != fptr[1] +out: + if(error < 0) { + result = 1; + puts("*FAILED - HDF5 library error*"); + } else if(fok[0] != fptr[0] || fok[1] != fptr[1] || fnok[0] != fptr[2] || fnok[1] != fptr[3]) { + char *mname; + result = 1; + mname = H5Tget_member_name(fix, 0); printf("%14s (%2d) %6s = %s\n", - mname = H5Tget_member_name(fix, 0), (int)H5Tget_member_offset(fix,0), + mname, (int)H5Tget_member_offset(fix,0), string5, (char *)(data + H5Tget_member_offset(fix, 0))); free(mname); + fptr = (float *)(data + H5Tget_member_offset(fix, 1)); + mname = H5Tget_member_name(fix, 1); printf("Data comparison:\n" "%14s (%2d) %6f = %f\n" " %6f = %f\n", - mname = H5Tget_member_name(fix, 1), (int)H5Tget_member_offset(fix,1), + mname, (int)H5Tget_member_offset(fix,1), fok[0], fptr[0], fok[1], fptr[1]); free(mname); + fptr = (float *)(data + H5Tget_member_offset(fix, 2)); + mname = H5Tget_member_name(fix, 2); printf("%14s (%2d) %6f = %f\n" " %6f = %6f\n", - mname = H5Tget_member_name(fix, 2), (int)H5Tget_member_offset(fix,2), + mname, (int)H5Tget_member_offset(fix,2), fnok[0], fptr[0], fnok[1], fptr[1]); free(mname); @@ -170,12 +182,13 @@ int main(void) fok[1], fptr[1], fnok[0], fptr[2], fnok[1], fptr[3]); - puts("*FAILED*"); + puts("*FAILED - compound type alignmnent problem*"); } else { puts(" PASSED"); } - free(data); + if(data) + free(data); H5Sclose(spc); H5Tclose(cmp); H5Tclose(cmp1); |