diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2011-10-09 07:03:10 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2011-10-09 07:03:10 (GMT) |
commit | ab4451e2dd2b683e1fa35b3e9a443b065c42b7cb (patch) | |
tree | be72ff28e29cb87e9657fcd52eef59aafe9fc8ba /src/H5MM.c | |
parent | 22dff7723c68e2fdba2844287f09a884dd9bc5da (diff) | |
download | hdf5-ab4451e2dd2b683e1fa35b3e9a443b065c42b7cb.zip hdf5-ab4451e2dd2b683e1fa35b3e9a443b065c42b7cb.tar.gz hdf5-ab4451e2dd2b683e1fa35b3e9a443b065c42b7cb.tar.bz2 |
[svn-r21496] - H5MM_strdup() and H5MM_xstrdup() comments changed to correctly reflect how they respond to an input NULL string.
- H5MM_xstrdup() now reports memory allocation errors via the HDF5 error stack (was previously an assert).
Tested on local Windows via ctest (trivial change).
Diffstat (limited to 'src/H5MM.c')
-rw-r--r-- | src/H5MM.c | 53 |
1 files changed, 25 insertions, 28 deletions
@@ -145,20 +145,18 @@ H5MM_realloc(void *mem, size_t size) /*------------------------------------------------------------------------- - * Function: H5MM_xstrdup + * Function: H5MM_xstrdup * - * Purpose: Duplicates a string. If the string to be duplicated is the - * null pointer, then return null. If the string to be duplicated - * is the empty string then return a new empty string. + * Purpose: Duplicates a string, including memory allocation. + * NULL is an acceptable value for the input string. * - * Return: Success: Ptr to a new string (or null if no string). + * Return: Success: Pointer to a new string (NULL if s is NULL). * - * Failure: abort() - * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Jul 10 1997 + * Failure: abort() * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 10 1997 *------------------------------------------------------------------------- */ char * @@ -166,49 +164,48 @@ H5MM_xstrdup(const char *s) { char *ret_value = NULL; - /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5MM_xstrdup) + FUNC_ENTER_NOAPI(H5MM_xstrdup, NULL) if(s) { - ret_value = (char *)H5MM_malloc(HDstrlen(s) + 1); - HDassert(ret_value); + if(NULL == (ret_value = (char *)H5MM_malloc(HDstrlen(s) + 1))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") HDstrcpy(ret_value, s); } /* end if */ +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5MM_xstrdup() */ /*------------------------------------------------------------------------- - * Function: H5MM_strdup + * Function: H5MM_strdup * - * Purpose: Duplicates a string. If the string to be duplicated is the - * null pointer, then return null. If the string to be duplicated - * is the empty string then return a new empty string. + * Purpose: Duplicates a string, including memory allocation. + * NULL is NOT an acceptable value for the input string. * - * Return: Success: Ptr to a new string (or null if no string). + * If the string to be duplicated is the NULL pointer, then + * an error will be raised. * - * Failure: abort() + * Return: Success: Pointer to a new string * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Jul 10 1997 - * - * Modifications: + * Failure: abort() * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 10 1997 *------------------------------------------------------------------------- */ char * H5MM_strdup(const char *s) { - char *ret_value; + char *ret_value; FUNC_ENTER_NOAPI(H5MM_strdup, NULL) if(!s) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "null string") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "null string") if(NULL == (ret_value = (char *)H5MM_malloc(HDstrlen(s) + 1))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") HDstrcpy(ret_value, s); done: |