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 /src/H5Tenum.c | |
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
Diffstat (limited to 'src/H5Tenum.c')
-rw-r--r-- | src/H5Tenum.c | 84 |
1 files changed, 46 insertions, 38 deletions
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); |