diff options
Diffstat (limited to 'tools/h5dump/h5dump.c')
-rw-r--r-- | tools/h5dump/h5dump.c | 23 |
1 files changed, 18 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() */ |