summaryrefslogtreecommitdiffstats
path: root/src/H5Pint.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2013-09-05 20:44:14 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2013-09-05 20:44:14 (GMT)
commit5b876c929f79003c85585570827452f5d8052d01 (patch)
tree89a1fa7bb8221a8679f180868467464e331c18ce /src/H5Pint.c
parenta1fe10691cf7ce1737aa420191efb996f7fe5657 (diff)
downloadhdf5-5b876c929f79003c85585570827452f5d8052d01.zip
hdf5-5b876c929f79003c85585570827452f5d8052d01.tar.gz
hdf5-5b876c929f79003c85585570827452f5d8052d01.tar.bz2
[svn-r24101] Description:
Clean up warnings, enable new compiler warning flag(s) and bring back changes from Coverity branch: r20813: Remove the dead code as listed for coverity bug #1722. h5committested. r20814: Issue 69: Check return value and throw error if negative return. Also free datatype id on error r20815: Use HDstrncpy. --gh r20816: Replaced one last HDstrcat call with HDstrncat to resolve coverity issue 832. r20817: Use HDstrncpy and HDstrncat. --gh r20818: Purpose: Fix valgrind issues with h5jam Description: Modified h5jam to free strings strdup'd in parse_command_line before exit. Note that they may still not be freed in case of error, due to the widespread use of exit(). r20819: Issue 80: change loop to use int as loop index. r20820: Maintenance: Fixed the bug found by coverity CID 788 There were two problems with this function: 1) it tried to unnecessary free NULL pointer 2) it tried to allocate c_name buffer that is done by H5Pget_class_name Tested on: Mac OSX 10.8.4 (amazon) w/gcc 4.8.1, C++ & FORTRAN (too minor to require h5committest)
Diffstat (limited to 'src/H5Pint.c')
-rw-r--r--src/H5Pint.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/H5Pint.c b/src/H5Pint.c
index 13cc3c1..40d0a9c 100644
--- a/src/H5Pint.c
+++ b/src/H5Pint.c
@@ -4787,9 +4787,6 @@ done:
char *
H5P_get_class_path(H5P_genclass_t *pclass)
{
- char *par_path; /* Parent class's full path */
- size_t par_path_len;/* Parent class's full path's length */
- size_t my_path_len; /* This class's name's length */
char *ret_value; /* return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -4797,33 +4794,32 @@ H5P_get_class_path(H5P_genclass_t *pclass)
HDassert(pclass);
/* Recursively build the full path */
- if(pclass->parent!=NULL) {
+ if(pclass->parent != NULL) {
+ char *par_path; /* Parent class's full path */
+
/* Get the parent class's path */
- par_path=H5P_get_class_path(pclass->parent);
- if(par_path!=NULL) {
- /* Get the string lengths we need to allocate space */
- par_path_len=HDstrlen(par_path);
- my_path_len=HDstrlen(pclass->name);
+ par_path = H5P_get_class_path(pclass->parent);
+ if(par_path != NULL) {
+ size_t ret_str_len;
/* Allocate enough space for the parent class's path, plus the '/'
* separator, this class's name and the string terminator
*/
- if(NULL == (ret_value = (char *)H5MM_malloc(par_path_len + 1 + my_path_len + 1)))
+ ret_str_len = HDstrlen(par_path) + 1 + HDstrlen(pclass->name) + 1;
+ if(NULL == (ret_value = (char *)H5MM_malloc(ret_str_len)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for class name")
/* Build the full path for this class */
- HDstrcpy(ret_value,par_path);
- HDstrcat(ret_value,"/");
- HDstrcat(ret_value,pclass->name);
+ HDsnprintf(ret_value, ret_str_len, "%s/%s", par_path, pclass->name);
/* Free the parent class's path */
H5MM_xfree(par_path);
} /* end if */
else
- ret_value=H5MM_xstrdup(pclass->name);
+ ret_value = H5MM_xstrdup(pclass->name);
} /* end if */
else
- ret_value=H5MM_xstrdup(pclass->name);
+ ret_value = H5MM_xstrdup(pclass->name);
done:
FUNC_LEAVE_NOAPI(ret_value)