diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2012-02-23 17:45:46 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2012-02-23 17:45:46 (GMT) |
commit | 9974e02bc07585de4fdfc1f0b2803a7370e37b4e (patch) | |
tree | 57d7b4b58179bc5dfca86c26c8fb5b834abd54e8 /tools/lib/h5tools_str.c | |
parent | c47f6becf2740a9e41824f522f33ada852fec26e (diff) | |
download | hdf5-9974e02bc07585de4fdfc1f0b2803a7370e37b4e.zip hdf5-9974e02bc07585de4fdfc1f0b2803a7370e37b4e.tar.gz hdf5-9974e02bc07585de4fdfc1f0b2803a7370e37b4e.tar.bz2 |
[svn-r21973] Correct limited reallocation on windows.
Tested: local linux, windows, h5committest
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r-- | tools/lib/h5tools_str.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index e1457e8..e5e0d64 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -123,15 +123,10 @@ 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) { - str->nalloc = STR_INIT_LEN; - str->s = HDmalloc(str->nalloc); - HDassert(str->s); - str->s[0] = '\0'; - str->len = 0; + h5tools_str_reset(str); } if (HDstrlen(fmt) == 0) { @@ -155,12 +150,16 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) * 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 + * Because of this different return results, the strlen of the new string * 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) { + if (nchars < 0 +#ifndef H5_VSNPRINTF_WORKS + && (strlen(str->s) < str->nalloc) +#endif + ) { /* failure, such as bad format */ return NULL; } @@ -177,7 +176,6 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) str->s = HDrealloc(str->s, newsize); HDassert(str->s); str->nalloc = newsize; - isReallocated = TRUE; } else { /* Success */ |