summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_str.c
diff options
context:
space:
mode:
authorJonathan Kim <jkm@hdfgroup.org>2011-03-08 15:24:17 (GMT)
committerJonathan Kim <jkm@hdfgroup.org>2011-03-08 15:24:17 (GMT)
commit8ff85dff9b88b79c16b5f1f23f054ab3216402bf (patch)
treef3a5717c2eb797cb65202dd92ec2d2ab2246a359 /tools/lib/h5tools_str.c
parent031d71a85b2e066cdb258341d667f9a959c5ba59 (diff)
downloadhdf5-8ff85dff9b88b79c16b5f1f23f054ab3216402bf.zip
hdf5-8ff85dff9b88b79c16b5f1f23f054ab3216402bf.tar.gz
hdf5-8ff85dff9b88b79c16b5f1f23f054ab3216402bf.tar.bz2
[svn-r20198] Purpose:
Fixing Bug 2161 - GMQS: h5dump - only on Windows, skip displaying a data value every a certain lines in array type dataset Description: Merged from HDF5 trunk r20188. 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)
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r--tools/lib/h5tools_str.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c
index 95b1f5b..7630e9a 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 */