diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2014-04-12 04:02:26 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2014-04-12 04:02:26 (GMT) |
commit | a791213860bee1a2990a9b502819f17abf7ff8a0 (patch) | |
tree | eb6a0fb329cf263a781901e4ecfad41809f76fbe /c++ | |
parent | 170b9d0eed23d84bfad64f216b8759b1dc40586c (diff) | |
download | hdf5-a791213860bee1a2990a9b502819f17abf7ff8a0.zip hdf5-a791213860bee1a2990a9b502819f17abf7ff8a0.tar.gz hdf5-a791213860bee1a2990a9b502819f17abf7ff8a0.tar.bz2 |
[svn-r25030] Purpose: Fix HDFFV-8658
Description:
Turned on warnings and removed some of those.
(merged from trunk-r24994)
Platforms tested:
Linux/ppc64 (ostrich)
Linux/32 2.6 (jam)
SunOS 5.11 (emu)
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5Location.cpp | 19 | ||||
-rw-r--r-- | c++/src/H5Location.h | 6 | ||||
-rw-r--r-- | c++/test/dsets.cpp | 6 | ||||
-rw-r--r-- | c++/test/h5cpputil.h | 13 | ||||
-rw-r--r-- | c++/test/tattr.cpp | 9 | ||||
-rw-r--r-- | c++/test/tcompound.cpp | 4 |
6 files changed, 42 insertions, 15 deletions
diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index ead5822..80e1462 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -488,7 +488,7 @@ void H5Location::removeComment(const H5std_string& name) const /// will be truncated to accommodate the null terminator. // Programmer Binh-Minh Ribler - Mar 2014 //-------------------------------------------------------------------------- -ssize_t H5Location::getComment(const char* name, const size_t buf_size, char* comment) const +ssize_t H5Location::getComment(const char* name, size_t buf_size, char* comment) const { // H5Oget_comment_by_name will get buf_size chars of the comment including // the null terminator @@ -502,7 +502,7 @@ ssize_t H5Location::getComment(const char* name, const size_t buf_size, char* co } // If the comment is longer than the provided buffer size, the C library // will not null terminate it - if (comment_len >= buf_size) + if ((size_t)comment_len >= buf_size) comment[buf_size-1] = '\0'; // Return the actual comment length, which might be different from buf_size @@ -519,7 +519,7 @@ ssize_t H5Location::getComment(const char* name, const size_t buf_size, char* co ///\exception H5::LocationException // Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) //-------------------------------------------------------------------------- -H5std_string H5Location::getComment(const char* name, const size_t buf_size) const +H5std_string H5Location::getComment(const char* name, size_t buf_size) const { // Initialize string to "", so that if there is no comment, the returned // string will be empty @@ -549,6 +549,10 @@ H5std_string H5Location::getComment(const char* name, const size_t buf_size) con // Used overloaded function ssize_t comment_len = getComment(name, tmp_len+1, comment_C); + if (comment_len < 0) + { + throw LocationException("H5Location::getComment", "H5Oget_comment_by_name failed"); + } // Convert the C comment to return comment = comment_C; @@ -568,7 +572,7 @@ H5std_string H5Location::getComment(const char* name, const size_t buf_size) con /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) //-------------------------------------------------------------------------- -H5std_string H5Location::getComment(const H5std_string& name, const size_t buf_size) const +H5std_string H5Location::getComment(const H5std_string& name, size_t buf_size) const { return(getComment(name.c_str(), buf_size)); } @@ -854,11 +858,14 @@ H5O_type_t H5Location::p_get_ref_obj_type(void *ref, H5R_type_t ref_type) const { H5O_type_t obj_type = H5O_TYPE_UNKNOWN; herr_t ret_value = H5Rget_obj_type2(getId(), ref_type, ref, &obj_type); - - if (obj_type == H5O_TYPE_UNKNOWN || obj_type >= H5O_TYPE_NTYPES) + if (ret_value < 0) { throw ReferenceException(inMemFunc("getRefObjType"), "H5Rget_obj_type2 failed"); } + if (obj_type == H5O_TYPE_UNKNOWN || obj_type >= H5O_TYPE_NTYPES) + { + throw ReferenceException(inMemFunc("getRefObjType"), "H5Rget_obj_type2 returned invalid type"); + } return(obj_type); } diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index c13c1c5..592f68d 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -103,9 +103,9 @@ class H5_DLLCPP H5Location : public IdComponent { void setComment(const H5std_string& comment) const; // Retrieves comment for the HDF5 object specified by its name. - ssize_t getComment(const char* name, const size_t buf_size, char* comment) const; - H5std_string getComment(const char* name, const size_t buf_size=0) const; - H5std_string getComment(const H5std_string& name, const size_t buf_size=0) const; + ssize_t getComment(const char* name, size_t buf_size, char* comment) const; + H5std_string getComment(const char* name, size_t buf_size=0) const; + H5std_string getComment(const H5std_string& name, size_t buf_size=0) const; // Removes the comment for the HDF5 object specified by its name. void removeComment(const char* name) const; diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index 6824403..d1ced1d 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -312,10 +312,14 @@ test_datasize(FileAccPropList &fapl) // Get the dimension sizes. hsize_t dims[2]; int n_dims = space.getSimpleExtentDims(dims); + if (n_dims < 0) + { + throw Exception("test_compression", "DataSpace::getSimpleExtentDims() failed"); + } // Calculate the supposed size. Size of each value is int (4), from // test_simple_io. - int expected_size = 4 * dims[0] * dims[1]; + size_t expected_size = 4 * dims[0] * dims[1]; // getInMemDataSize() returns the in memory size of the data. size_t ds_size = dset.getInMemDataSize(); diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h index bea08d3..8625213 100644 --- a/c++/test/h5cpputil.h +++ b/c++/test/h5cpputil.h @@ -115,6 +115,19 @@ template <class Type1, class Type2> } } +template <class Type1, class Type2> + void CHECK(Type1 x, Type2 value, const char* msg, int line, const char* file_name) +{ + if (x == value) + { + cerr << endl; + cerr << "*** Function " << msg << " FAILED at line " << line << endl; + IncTestNumErrs(); + throw TestFailedException(file_name, msg); + } +} + + /* Prototypes for the test routines */ #ifdef __cplusplus extern "C" { diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 72da288..e333e3f 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -292,7 +292,8 @@ static void test_attr_getname() HDmemset(fattr1_name, 0, buf_size+1); ssize_t name_size = 0; // actual length of attribute name name_size = fattr1.getName(fattr1_name, buf_size+1); - verify_val(name_size, FATTR1_NAME.length(), "Attribute::getName", __LINE__, __FILE__); + CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); + verify_val((size_t)name_size, FATTR1_NAME.length(), "Attribute::getName", __LINE__, __FILE__); verify_val((const char*)fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); delete []fattr1_name; @@ -303,7 +304,8 @@ static void test_attr_getname() fattr1_name = new char[buf_size+1]; HDmemset(fattr1_name, 0, buf_size+1); name_size = fattr1.getName(fattr1_name, buf_size+1); - verify_val(name_size, FATTR1_NAME.length(), "Attribute::getName", __LINE__, __FILE__); + CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); + verify_val((size_t)name_size, FATTR1_NAME.size(), "Attribute::getName", __LINE__, __FILE__); verify_val((const char*)fattr1_name, (const char*)short_name, "Attribute::getName", __LINE__, __FILE__); delete []fattr1_name; @@ -312,6 +314,7 @@ static void test_attr_getname() fattr1_name = new char[buf_size+1]; HDmemset(fattr1_name, 0, buf_size+1); name_size = fattr1.getName(fattr1_name, buf_size+1); + CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); verify_val(fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); delete []fattr1_name; @@ -609,7 +612,7 @@ static void test_attr_compound_read() size_t size; // Attribute datatype size as stored in file size_t offset; // Attribute datatype field offset struct attr4_struct read_data4[ATTR4_DIM1][ATTR4_DIM2]; // Buffer for reading 4th attribute - int i,j; + hsize_t i,j; // Output message about test being performed SUBTEST("Basic Attribute Functions"); diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp index d8e381b..62a90e8 100644 --- a/c++/test/tcompound.cpp +++ b/c++/test/tcompound.cpp @@ -793,7 +793,7 @@ static void test_compound_set_size() // Verify setSize() actually set size size_t new_size = dtype.getSize(); - verify_val(new_size, 33, "DataType::getSize", __LINE__, __FILE__); + verify_val(new_size, (size_t)33, "DataType::getSize", __LINE__, __FILE__); // Shrink the type, and verify that it became packed dtype.setSize((size_t)32); @@ -802,7 +802,7 @@ static void test_compound_set_size() // Verify setSize() actually set size again new_size = dtype.getSize(); - verify_val(new_size, 32, "DataType::getSize", __LINE__, __FILE__); + verify_val(new_size, (size_t)32, "DataType::getSize", __LINE__, __FILE__); /* Close types and file */ dtype_tmp.close(); |