diff options
author | Jonathan Kim <jkm@hdfgroup.org> | 2011-03-04 16:21:26 (GMT) |
---|---|---|
committer | Jonathan Kim <jkm@hdfgroup.org> | 2011-03-04 16:21:26 (GMT) |
commit | 0619b155aaaa2ca002bcbadba081c137d9554d24 (patch) | |
tree | 8f301ed1061d1bbfb9678adb2b306f5c20805f92 /tools/lib | |
parent | 190878d7977ab052cf4eaa5a2819cc8e4c59628c (diff) | |
download | hdf5-0619b155aaaa2ca002bcbadba081c137d9554d24.zip hdf5-0619b155aaaa2ca002bcbadba081c137d9554d24.tar.gz hdf5-0619b155aaaa2ca002bcbadba081c137d9554d24.tar.bz2 |
[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)
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5tools_str.c | 17 |
1 files changed, 15 insertions, 2 deletions
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 */ |