diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-01-24 03:26:37 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-01-24 03:26:37 (GMT) |
commit | 563a8dd1401c2f3c04b897f2a727d7d6ac9b141f (patch) | |
tree | 4a62599af4c3f8e1d7d9f007a11fc2fbe0f18cab /src/H5E.c | |
parent | d363f95d6d7c8ac25ccf319e9d136fc5842b9474 (diff) | |
download | hdf5-563a8dd1401c2f3c04b897f2a727d7d6ac9b141f.zip hdf5-563a8dd1401c2f3c04b897f2a727d7d6ac9b141f.tar.gz hdf5-563a8dd1401c2f3c04b897f2a727d7d6ac9b141f.tar.bz2 |
[svn-r9861] Purpose:
Bug fix
Description:
Add detect vasprintf() routine and use it instead of vsnprintf() when
formatting error descriptions if it's available.
Added configure test to detect "broken" vsnprintf() implementations which
don't return the correct number of character for strings that are too long to
fit into the buffer provided (currently a problem on the SGIs and probably the
HP).
Re-wrote error formatting code in H5Epush_stack() to handle broken
vsnprintf() implementations, etc.
Platforms tested:
IRIX64 6.5 (modi4)
h5committest
Diffstat (limited to 'src/H5E.c')
-rw-r--r-- | src/H5E.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1513,13 +1513,24 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line /* Format the description */ va_start(ap, fmt); +#ifdef H5_HAVE_VASPRINTF + /* Use the vasprintf() routine, since it does what we're trying to do below */ + if(HDvasprintf(&tmp,fmt,ap)<0) + HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") +#else /* H5_HAVE_VASPRINTF */ /* Allocate space for the formatted description buffer */ tmp_len=128; if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* 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))>tmp_len) { + 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)) { /* shutdown & restart the va_list */ va_end(ap); va_start(ap, fmt); @@ -1528,10 +1539,15 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line H5MM_xfree(tmp); /* Allocate a description of the appropriate length */ +#ifdef H5_VSNPRINTF_WORKS tmp_len = desc_len+1; +#else /* H5_VSNPRINTF_WORKS */ + tmp_len = 2 * desc_len; +#endif /* H5_VSNPRINTF_WORKS */ if((tmp=H5MM_malloc((size_t)tmp_len))==NULL) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") } /* end while */ +#endif /* H5_HAVE_VASPRINTF */ va_end(ap); |