From 268d79925ba45493c259a96c72c3e89f9d6472c3 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 11 Oct 2011 15:33:13 -0500 Subject: [svn-r21522] - 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 jam (simple change). --- src/H5MM.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/H5MM.c b/src/H5MM.c index c27f9d1..5555fc9 100644 --- a/src/H5MM.c +++ b/src/H5MM.c @@ -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,36 +164,35 @@ 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 * -- cgit v0.12