From 24c134e28b8f2229d91a5a48ac285bf6f5fc5b94 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Mon, 24 Jan 2005 13:50:31 -0500 Subject: [svn-r9865] Purpose: Bug fix Description: Catch another way that vsnprintf() can fail (this time on the HP) and deal with that. Platforms tested: HP/UX 11.x (kelgia) Doesn't affect other platforms --- configure | 4 ++-- configure.in | 12 ++++++++++-- src/H5E.c | 14 +++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/configure b/configure index bc4a442..5fc46fe 100755 --- a/configure +++ b/configure @@ -31003,7 +31003,7 @@ if test `eval echo '${'$as_ac_var'}'` = yes; then cat >>confdefs.h <<_ACEOF #define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF - echo "$as_me:$LINENO: checking if vsnprintf returns correct value" >&5 + echo "$as_me:$LINENO: checking if vsnprintf returns correct value" >&5 echo $ECHO_N "checking if vsnprintf returns correct value... $ECHO_C" >&6 if test "${hdf5_cv_vsnprintf_works+set}" = set; then @@ -31032,7 +31032,7 @@ int test_vsnprintf(const char *fmt,...) ret=vsnprintf(s,16,"%s",ap); va_end(ap); - return(ret==15 ? 1 : 0); + return(ret!=42 ? 1 : 0); } int main(void) diff --git a/configure.in b/configure.in index 09ae750..183588b 100644 --- a/configure.in +++ b/configure.in @@ -1653,7 +1653,15 @@ AC_CHECK_FUNCS(vsnprintf, dnl Check if vsnprintf() returns correct size for strings that don't fit dnl into the size allowed. If vsnprintf() works correctly on this platform, - dnl it should return a value larger than 15 for the test below + dnl it should return a value of 42 for the test below + dnl + dnl Note that vsnprintf fails in two different ways: + dnl - In IRIX64, calls to vnsprintf() with a formatted string that + dnl is larger than the buffer size allowed incorrectly + dnl return the size of the buffer minus one. + dnl - In HP/UX, calls to vsnprintf() with a formatted string that + dnl is larger than the buffer size allowed incorrectly + dnl return (-1) AC_MSG_CHECKING([if vsnprintf returns correct value]) AC_CACHE_VAL([hdf5_cv_vsnprintf_works], @@ -1672,7 +1680,7 @@ int test_vsnprintf(const char *fmt,...) ret=vsnprintf(s,16,"%s",ap); va_end(ap); - return(ret==15 ? 1 : 0); + return(ret!=42 ? 1 : 0); } int main(void) diff --git a/src/H5E.c b/src/H5E.c index 31d212f..20d3604 100644 --- a/src/H5E.c +++ b/src/H5E.c @@ -1384,7 +1384,7 @@ done: * *------------------------------------------------------------------------- */ -herr_t +static herr_t H5E_pop(H5E_t *estack, size_t count) { herr_t ret_value = SUCCEED; /* Return value */ @@ -1526,11 +1526,15 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line /* If the description doesn't fit into the initial buffer size, allocate more space and try again */ while((desc_len=HDvsnprintf(tmp, (size_t)tmp_len, fmt, ap)) #ifdef H5_VSNPRINTF_WORKS - > + > #else /* H5_VSNPRINTF_WORKS */ - >= + >= +#endif /* H5_VSNPRINTF_WORKS */ + (tmp_len-1) +#ifndef H5_VSNPRINTF_WORKS + || desc_len<0 #endif /* H5_VSNPRINTF_WORKS */ - (tmp_len-1)) { + ) { /* shutdown & restart the va_list */ va_end(ap); va_start(ap, fmt); @@ -1542,7 +1546,7 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line #ifdef H5_VSNPRINTF_WORKS tmp_len = desc_len+1; #else /* H5_VSNPRINTF_WORKS */ - tmp_len = 2 * desc_len; + tmp_len = 2 * tmp_len; #endif /* H5_VSNPRINTF_WORKS */ if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") -- cgit v0.12