From 67be45610fd450909038afea54f79e6a91c458cf Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sat, 22 Mar 2014 15:39:44 -0500 Subject: [svn-r24867] Description: - Added a null terminator to the comment returned from the C call, in getComment methods - Some minor cleanup Platforms tested: Linux/ppc64 (ostrich) Linux/32 2.6 (jam) Linux/64 2.6 (platypus)/PGI compilers --- c++/src/H5Attribute.h | 2 +- c++/src/H5File.h | 12 ++++++++---- c++/src/H5Group.h | 2 -- c++/src/H5Location.cpp | 8 ++++++-- c++/test/dsets.cpp | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index dbfbbb2..4f15c7f 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -60,7 +60,7 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { void write(const DataType& mem_type, const H5std_string& strg ) const; // Flushes all buffers associated with the file specified by this - // attribute to disk + // attribute to disk. void flush( H5F_scope_t scope ) const; ///\brief Returns this class name. diff --git a/c++/src/H5File.h b/c++/src/H5File.h index 5fdbcdc..694d688 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -76,7 +76,14 @@ class H5_DLLCPP H5File : public H5Location, public CommonFG { // Reopens this file. void reOpen(); // added for better name - void reopen(); + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + void reopen(); // obsolete in favor of reOpen() + + // Gets the file id + virtual hid_t getLocId() const; + +#endif // DOXYGEN_SHOULD_SKIP_THIS ///\brief Returns this class name. virtual H5std_string fromClass () const { return("H5File"); } @@ -84,9 +91,6 @@ class H5_DLLCPP H5File : public H5Location, public CommonFG { // Throw file exception. virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const; - // Gets the file id - virtual hid_t getLocId() const; - // Default constructor H5File(); diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index 78f5f17..1bd9882 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -42,8 +42,6 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { // Creates a group by way of dereference. Group(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); - /* Group(H5File& h5file, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - */ Group(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); // default constructor diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index fdbfd61..3240f70 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -500,8 +500,12 @@ ssize_t H5Location::getComment(const char* name, const size_t buf_size, char* co { throw LocationException("H5Location::getComment", "H5Oget_comment_by_name failed"); } + // If the comment is longer than the provided buffer size, the C library + // will not null terminate it + if (comment_len >= buf_size) + comment[buf_size-1] = '\0'; - // Return the comment length, which might be different from buf_size + // Return the actual comment length, which might be different from buf_size return(comment_len); } @@ -544,7 +548,7 @@ H5std_string H5Location::getComment(const char* name, const size_t buf_size) con HDmemset(comment_C, 0, tmp_len+1); // clear buffer // Used overloaded function - ssize_t comment_len = getComment(name, tmp_len, comment_C); + ssize_t comment_len = getComment(name, tmp_len+1, comment_C); // Convert the C comment to return comment = comment_C; diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index b6922c2..72d7977 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -1075,7 +1075,7 @@ void test_dset() // Get part of the comment, random length using // ssize_t getComment(const char* name, const size_t buf_size, char* comment) char* comment = new char[11]; - ssize_t comment_len = file.getComment("emit diagnostics", 10, comment); + ssize_t comment_len = file.getComment("emit diagnostics", 11, comment); verify_val((const char*)comment, "Causes dia", "H5Location::getComment", __LINE__, __FILE__); // Close group "emit diagnostics". -- cgit v0.12