summaryrefslogtreecommitdiffstats
path: root/tools/h5dump
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2011-02-04 20:35:25 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2011-02-04 20:35:25 (GMT)
commit89a47692e9d14798dd2e7506a34f74810c1259dc (patch)
treea9fd7dcda8baeca8c611f7f0ea312f6a84a1b73e /tools/h5dump
parentba13827093c38cb9d87ae87e59d47a34415c88cb (diff)
downloadhdf5-89a47692e9d14798dd2e7506a34f74810c1259dc.zip
hdf5-89a47692e9d14798dd2e7506a34f74810c1259dc.tar.gz
hdf5-89a47692e9d14798dd2e7506a34f74810c1259dc.tar.bz2
[svn-r20044] Fix bz2127 by dynamically allocating storgae for comments.
Tested: local linux
Diffstat (limited to 'tools/h5dump')
-rw-r--r--tools/h5dump/h5dump.c23
-rw-r--r--tools/h5dump/h5dumpgentest.c5
2 files changed, 23 insertions, 5 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 33750f3..40a37af 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -2646,15 +2646,28 @@ dump_oid(hid_t oid)
static void
dump_comment(hid_t obj_id)
{
- char comment[50];
-
- comment[0] = '\0';
- H5Oget_comment(obj_id, comment, sizeof(comment));
+ size_t buf_size = 0;
+ char* comment = NULL;
+ ssize_t cmt_bufsize = -1;
+
+ cmt_bufsize = H5Oget_comment(obj_id, comment, buf_size);
+
+ // if the actual length of the comment is longer than cmt_bufsize, then call
+ // H5Oget_comment again with the correct value.
+ // If the call to H5Oget_comment returned an error, skip this block
+ if (cmt_bufsize >= 0) {
+ comment = (char *)HDmalloc((size_t)cmt_bufsize++); // new_size including null terminator
+ if(comment)
+ cmt_bufsize = H5Oget_comment(obj_id, comment, cmt_bufsize);
+ }
- if(comment[0]) {
+ if(cmt_bufsize > 0) {
+ comment[cmt_bufsize] = '\0';
indentation(indent);
printf("COMMENT \"%s\"\n", comment);
} /* end if */
+ if(comment)
+ HDfree(comment);
} /* end dump_comment() */
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index 7701651..8401000 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -3400,6 +3400,11 @@ gent_group_comments(void)
H5Oset_comment_by_name(group, "/g2/g2.1/g2.1.3", "Comment for group /g2/g2.1/g2.1.3", H5P_DEFAULT);
H5Gclose(group);
+ /* /glongcomment */
+ group = H5Gcreate2(fid, "/glongcomment", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Oset_comment_by_name(group, "/glongcomment", "Comment for group /glongcomment with a really, really, really long, long, long comment", H5P_DEFAULT);
+ H5Gclose(group);
+
H5Fclose(fid);
}