From 89a47692e9d14798dd2e7506a34f74810c1259dc Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 4 Feb 2011 15:35:25 -0500 Subject: [PATCH] [svn-r20044] Fix bz2127 by dynamically allocating storgae for comments. Tested: local linux --- MANIFEST | 1 + tools/h5dump/h5dump.c | 21 +++++++++++++++++---- tools/h5dump/h5dumpgentest.c | 5 +++++ tools/h5ls/CMakeLists.txt | 7 +++++++ tools/h5ls/h5ls.c | 22 +++++++++++++++++----- tools/h5ls/testh5ls.sh.in | 3 +++ tools/testfiles/tgrp_comments.ddl | 3 +++ tools/testfiles/tgrp_comments.h5 | Bin 14336 -> 13248 bytes tools/testfiles/tgrp_comments.ls | 8 ++++++++ 9 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 tools/testfiles/tgrp_comments.ls diff --git a/MANIFEST b/MANIFEST index a08b16fa47..247cc69f5e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1249,6 +1249,7 @@ ./tools/testfiles/tgroup-1.ddl ./tools/testfiles/tgroup-2.ddl ./tools/testfiles/tgroup.h5 +./tools/testfiles/tgrp_comments.ls ./tools/testfiles/tgrp_comments.ddl ./tools/testfiles/tgrp_comments.h5 ./tools/testfiles/thlink-1.ddl diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 33750f3c8e..40a37afa57 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]; + size_t buf_size = 0; + char* comment = NULL; + ssize_t cmt_bufsize = -1; - comment[0] = '\0'; - H5Oget_comment(obj_id, comment, sizeof(comment)); + cmt_bufsize = H5Oget_comment(obj_id, comment, buf_size); - if(comment[0]) { + // 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(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 770165149d..8401000f06 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); } diff --git a/tools/h5ls/CMakeLists.txt b/tools/h5ls/CMakeLists.txt index 3039682131..7db6c7fefa 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 b74d52562b..051821e2cb 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 a9964015aa..3083028e6b 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 diff --git a/tools/testfiles/tgrp_comments.ddl b/tools/testfiles/tgrp_comments.ddl index 6321b36daa..460a9f0383 100644 --- a/tools/testfiles/tgrp_comments.ddl +++ b/tools/testfiles/tgrp_comments.ddl @@ -42,5 +42,8 @@ GROUP "/" { COMMENT "Comment for group /g3/g3.4" } } + GROUP "glongcomment" { + COMMENT "Comment for group /glongcomment with a really, really, really long, long, long comment" + } } } diff --git a/tools/testfiles/tgrp_comments.h5 b/tools/testfiles/tgrp_comments.h5 index 70c7cce76b44509a9331cbf1f286f1c2fdf001a6..ddd2eec37cc39d0aa95575ecdaec0005030b0d67 100644 GIT binary patch literal 13248 zcmeHO&rcIU6rO^{N^FE^6o18uM$;IyKsj(+Bbc7FQ4c*r2reW*8-fvU9P7;^#~wL) z^w=Xu|AZcU^gqzuec!jClg@61Hr949*|%@@&Cbm0_rCXLYQL6NUgxInPO0!On^l+8 zbaczhZ~Qfj(n6ij*Km`8tV5nm$W2Ct|CE|V`wZT1+I@Jpx~c+8zMm4^RO_IROK(ooxcbP-13hx&Fe72*H7j5KNqUH26#T{>|H!Ou*_{ z^wX1a!}pe;Z($z9=Nj-$yE^oftJ0tIuSn*I%v|A{z-+0Y8+ zEz@5)WVTmAE&5}1U;F#jPc>bLsK~}28h+}PKPtDyHT)ch)=_R^1Mz^#AB@ve#3Kjw z7ll6NBH zphuNoAeTZL#skt0yICc1Z|1Wk+=m0&a9^2`p*)Nz^`f%wcO35Fs4*2L?wR+0T<>%U zab50gKDQ?I;zV38mciE?=Mefa=D|F441CkB3B7gW+*A3lJCZ+4f8~^p*44FM3`#~} zu>>BuDQ@vZD90mkgcDsoVB--59I+GQwqHC#{F^+Giht|}ZF#hTji-l+r=7dBQ7~}7 z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diff --git a/tools/testfiles/tgrp_comments.ls b/tools/testfiles/tgrp_comments.ls new file mode 100644 index 0000000000..e4c7d42d4e --- /dev/null +++ b/tools/testfiles/tgrp_comments.ls @@ -0,0 +1,8 @@ +############################# + output for 'h5ls -w80 -v -g tgrp_comments.h5/glongcomment' +############################# +Opened "tgrp_comments.h5" with sec2 driver. +glongcomment Group + Location: 1:12424 + Links: 1 + Comment: "Comment for group /glongcomment with a really, really, really long, long, long comment"