diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2011-02-04 20:36:24 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2011-02-04 20:36:24 (GMT) |
commit | 229e13fecec59da3680a17020c74fd44ca82ff54 (patch) | |
tree | 2a2262691bc8cb596a52faf3489625c15753caba /tools/h5ls | |
parent | 641a70b7e0e9c7516c830f309d93c456a546e385 (diff) | |
download | hdf5-229e13fecec59da3680a17020c74fd44ca82ff54.zip hdf5-229e13fecec59da3680a17020c74fd44ca82ff54.tar.gz hdf5-229e13fecec59da3680a17020c74fd44ca82ff54.tar.bz2 |
[svn-r20045] Fix bz2127 by dynamically allocating storgae for comments.
Bring 20044 from trunk
Tested: local linux
Diffstat (limited to 'tools/h5ls')
-rw-r--r-- | tools/h5ls/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tools/h5ls/h5ls.c | 22 | ||||
-rw-r--r-- | tools/h5ls/testh5ls.sh.in | 3 |
3 files changed, 27 insertions, 5 deletions
diff --git a/tools/h5ls/CMakeLists.txt b/tools/h5ls/CMakeLists.txt index 3039682..7db6c7f 100644 --- a/tools/h5ls/CMakeLists.txt +++ b/tools/h5ls/CMakeLists.txt @@ -62,6 +62,7 @@ IF (BUILD_TESTING) tsoftlinks-5.ls textlinksrc-nodangle-1.ls textlinksrc-nodangle-2.ls + tgrp_comments.ls tsoftlinks-nodangle-1.ls thlinks-nodangle-1.ls tgroup.ls @@ -94,6 +95,7 @@ IF (BUILD_TESTING) textlinksrc.h5 textlinktar.h5 tgroup.h5 + tgrp_comments.h5 thlink.h5 tloop.h5 tnestedcomp.h5 @@ -210,6 +212,8 @@ IF (BUILD_TESTING) textlinksrc-6-old.out.err textlinksrc-7-old.out textlinksrc-7-old.out.err + tgrp_comments.out + tgrp_comments.out.err tsoftlinks-1.out tsoftlinks-1.out.err tsoftlinks-2.out @@ -288,6 +292,9 @@ IF (BUILD_TESTING) ADD_H5_TEST (tgroup-1 1 -w80 -r -g tgroup.h5) ADD_H5_TEST (tgroup-2 0 -w80 -g tgroup.h5/g1) + # test for files with groups that have long comments + ADD_H5_TEST (tgrp_comments 0 -w80 -v -g tgrp_comments.h5/glongcomment) + # test for displaying simple space datasets ADD_H5_TEST (tdset-1 0 -w80 -r -d tdset.h5) diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index b74d525..051821e 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -1785,7 +1785,9 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void /* Show detailed information about the object, beginning with information * which is common to all objects. */ if(verbose_g > 0) { - char comment[50]; + size_t buf_size = 0; + char* comment = NULL; + ssize_t cmt_bufsize = -1; /* Display attributes */ if(obj_type >= 0) @@ -1811,14 +1813,24 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void } /* end if */ /* Object comment */ - comment[0] = '\0'; - H5Oget_comment(obj, comment, sizeof(comment)); - HDstrcpy(comment + sizeof(comment) - 4, "..."); - if(comment[0]) { + cmt_bufsize = H5Oget_comment(obj, 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, comment, cmt_bufsize); + } + if(cmt_bufsize > 0) { + comment[cmt_bufsize] = '\0'; printf(" %-10s \"", "Comment:"); display_string(stdout, comment, FALSE); puts("\""); } /* end if */ + if(comment) + HDfree(comment); } /* end if */ /* Detailed list for object */ diff --git a/tools/h5ls/testh5ls.sh.in b/tools/h5ls/testh5ls.sh.in index a996401..3083028 100644 --- a/tools/h5ls/testh5ls.sh.in +++ b/tools/h5ls/testh5ls.sh.in @@ -135,6 +135,9 @@ TOOLTEST tgroup-3.ls 0 -w80 tgroup.h5/g1 TOOLTEST tgroup-1.ls 1 -w80 -r -g tgroup.h5 TOOLTEST tgroup-2.ls 0 -w80 -g tgroup.h5/g1 +# test for files with groups that have long comments +TOOLTEST tgrp_comments.ls 0 -w80 -v -g tgrp_comments.h5/glongcomment + # test for displaying simple space datasets TOOLTEST tdset-1.ls 0 -w80 -r -d tdset.h5 |