diff options
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5CommonFG.cpp | 6 | ||||
-rw-r--r-- | c++/test/trefer.cpp | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 0b9c25a..d69a20c 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -570,8 +570,10 @@ H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const // if the actual length of the comment is longer than bufsize and bufsize // was the default value, i.e., not given by the user, then call - // H5Oget_comment_by_name again with the correct value - if ((size_t)ret_value > bufsize && bufsize == 256) + // H5Oget_comment_by_name again with the correct value. + // If the call to H5Oget_comment_by_name returned an error, skip this block + // and throw an exception below. + if (ret_value >= 0 && (size_t)ret_value > bufsize && bufsize == 256) { size_t new_size = ret_value; delete []comment_C; diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index f17f37a..c4ac93b 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -217,6 +217,12 @@ static void test_reference_obj(void) H5std_string read_comment1 = group.getComment(".", 10); verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__); + // Test that getComment handles failures gracefully + try { + H5std_string read_comment_tmp = group.getComment(NULL); + } + catch (Exception E) {} // We expect this to fail + // Close group group.close(); |