From 0619b155aaaa2ca002bcbadba081c137d9554d24 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Fri, 4 Mar 2011 11:21:26 -0500 Subject: [svn-r20188] Purpose: Fixing Bug 2161 - GMQS: h5dump - only on Windows, skip displaying a data value every a certain lines in array type dataset Description: Fixed h5dump for skipping some values for long array type dataset on Windows. This issue only occurred on Windows due to the different return behavior from _vsnprintf() funtion. Tested: Windows, jam (linux32-LE), amani (linux64-LE), heiwa (linuxppc64-BE), tejeda (mac32-LE), linew (solaris-BE) --- release_docs/RELEASE.txt | 3 +++ tools/lib/h5tools_str.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index bf96077..91a92e7 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -500,6 +500,9 @@ Bug Fixes since HDF5-1.8.0 release Tools ----- + - Fixed h5dump for skipping some values for long array type dataset on + Windows. This issue only occurred on Windows due to the different + return behavior from _vsnprintf() funtion. Bug#2161 (JKM 2011/3/3) - Fixed h5dump for skipping array indices every certain number when the array type dataset is relatively big. The certain number varies according to the size of array. Bug#2092 (JKM 2011/2/15). diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 8c9960f..c1c6d72 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -123,6 +123,7 @@ char * h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) { va_list ap; + hbool_t isReallocated = FALSE; /* Make sure we have some memory into which to print */ if (!str->s || str->nalloc <= 0) { @@ -148,12 +149,23 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) nchars = HDvsnprintf(str->s + str->len, avail, fmt, ap); va_end(ap); - if (nchars < 0) { + /* Note: HDvsnprintf() behaves differently on Windows as Unix, when + * buffer is smaller than source string. On Unix, this function + * returns length of the source string and copy string upto the + * buffer size with NULL at the end of the buffer. However on + * Windows with the same condition, this function returns -1 and + * doesn't add NULL at the end of the buffer. + * Because of this different return results, isReallocated variable + * is used to handle when HDvsnprintf() returns -1 on Windows due + * to lack of buffer size, so try one more time after realloc more + * buffer size before return NULL. + */ + if (nchars < 0 && isReallocated == TRUE) { /* failure, such as bad format */ return NULL; } - if ((size_t) nchars >= avail || (0 == nchars && (strcmp(fmt, "%s")))) { + if (nchars < 0 || (size_t) nchars >= avail || (0 == nchars && (strcmp(fmt, "%s")))) { /* Truncation return value as documented by C99, or zero return value with either of the * following conditions, each of which indicates that the proper C99 return value probably * should have been positive when the format string is @@ -165,6 +177,7 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) str->s = realloc(str->s, newsize); assert(str->s); str->nalloc = newsize; + isReallocated = TRUE; } else { /* Success */ -- cgit v0.12