summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2013-02-02 01:53:32 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2013-02-02 01:53:32 (GMT)
commita3e98d0e36a0fbd6caae0a4a83863a78c2e25f50 (patch)
tree14e6c86e83d0b65e7033f9d31b0163404b41e36d /c++
parent5140343f45312d4d2e486e6cc7645c7bc42b1267 (diff)
downloadhdf5-a3e98d0e36a0fbd6caae0a4a83863a78c2e25f50.zip
hdf5-a3e98d0e36a0fbd6caae0a4a83863a78c2e25f50.tar.gz
hdf5-a3e98d0e36a0fbd6caae0a4a83863a78c2e25f50.tar.bz2
[svn-r23219] Description:
Bring reviewed changes from Coverity branch back to trunk (QK & JK): r20457: Coverity issue 691: return of H5duo could be negative. Fixed by using STDOUT_FILENO and redesign parse_command_line and main to cleanup file allocations. The output_file var is null when using stdout. In cleanup do not close output_file if NULL. r20510: Initialize ufid = -1 and predicate HDclose call on ufid != -1 r20511: Purpose: Fix coverity issue 1715 Description: Free "file" and nested data on failure in H5FD_core_open. r20512: Initialize ifid = -1 and predicate HDclose call on ifid != -1 r20514: Initialize h5fid = -1 and predicate HDclose call on h5fid != -1 r20516: Added else branch to the if (ret_value < 0) check. r20522: Addressed coverity issues 930-933, 850, 836, 835, 1307. All minor potential buffer overwrite bugs, or coverity errors. Fixed by replacing strcpy and sprintf with strncpy and snprintf. r20523: fixed coverity issues 68, 1120, 1116i r20524: Check H5Z_SZIP->encoder_present < 1 assuming 0 represents absence. r20601: Purpose: Fix coverity issues 1703-1705 Description: Modified the cleanup code in test_free in accum.c to reset allocated buffers to NULL after they are freed, and modified the error cleanup code to check if these buffers are NULL before freeing them. Also fixed some unrelated warnings in accum.c. r20602: Use HDsnprintf and HDstrncat r20603: Purpose: Fix coverity issues 808-809 Description: Modified test_core in vfd.c to check the returns from malloc, and keep track of whether points and check are allocated by setting them to NULL when they are not. Added code to free points and check on error if they are not NULL. Also fixed unrelated warnings in vfd.c. r20604: Use HDstrncpy. r20605: Use HDstrncpy and HDstrncat. r20606: Purpose: Fix coverity issue 807 Description: Modified long_compact in stab.c to keep track of whether objname is allocated by setting it to NULL when it is not. Added code to free objname on error if it is not NULL. r20607: Changed string function calls to use versions that specify the string length to fix coverity issues 832 and 839. Tested on: Mac OSX/64 10.8.2 (amazon) (Too minor to require h5committest)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5CommonFG.cpp49
1 files changed, 7 insertions, 42 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index dcc331f..b3889a0 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -130,9 +130,7 @@ Group CommonFG::openGroup( const char* name ) const
// If the opening of the group failed, throw an exception
if( group_id < 0 )
- {
throwException("openGroup", "H5Gopen2 failed");
- }
// No failure, create and return the Group object
Group group( group_id );
@@ -174,9 +172,7 @@ DataSet CommonFG::createDataSet( const char* name, const DataType& data_type, co
// If the creation of the dataset failed, throw an exception
if( dataset_id < 0 )
- {
throwException("createDataSet", "H5Dcreate2 failed");
- }
// No failure, create and return the DataSet object
DataSet dataset( dataset_id );
@@ -270,9 +266,8 @@ void CommonFG::link( H5L_type_t link_type, const char* curr_name, const char* ne
break;
} /* end switch */
- if( ret_value < 0 ) {
+ if( ret_value < 0 )
throwException("link", "creating link failed");
- }
}
//--------------------------------------------------------------------------
@@ -300,9 +295,7 @@ void CommonFG::unlink( const char* name ) const
{
herr_t ret_value = H5Ldelete( getLocId(), name, H5P_DEFAULT );
if( ret_value < 0 )
- {
throwException("unlink", "H5Ldelete failed");
- }
}
//--------------------------------------------------------------------------
@@ -336,9 +329,7 @@ void CommonFG::move( const char* src, const char* dst ) const
{
herr_t ret_value = H5Lmove( getLocId(), src, H5L_SAME_LOC, dst, H5P_DEFAULT, H5P_DEFAULT );
if( ret_value < 0 )
- {
throwException("move", "H5Lmove failed");
- }
}
//--------------------------------------------------------------------------
@@ -371,9 +362,7 @@ void CommonFG::getObjinfo( const char* name, hbool_t follow_link, H5G_stat_t& st
{
herr_t ret_value = H5Gget_objinfo( getLocId(), name, follow_link, &statbuf );
if( ret_value < 0 )
- {
throwException("getObjinfo", "H5Gget_objinfo failed");
- }
}
//--------------------------------------------------------------------------
@@ -400,9 +389,7 @@ void CommonFG::getObjinfo( const char* name, H5G_stat_t& statbuf ) const
{
herr_t ret_value = H5Gget_objinfo( getLocId(), name, 0, &statbuf );
if( ret_value < 0 )
- {
throwException("getObjinfo", "H5Gget_objinfo failed");
- }
}
//--------------------------------------------------------------------------
@@ -440,9 +427,8 @@ H5std_string CommonFG::getLinkval( const char* name, size_t size ) const
{
ret_value = H5Lget_info(getLocId(), name, &linkinfo, H5P_DEFAULT);
if( ret_value < 0 )
- {
throwException("getLinkval", "H5Lget_info to find buffer size failed");
- }
+
val_size = linkinfo.u.val_size;
}
@@ -453,9 +439,8 @@ H5std_string CommonFG::getLinkval( const char* name, size_t size ) const
ret_value = H5Lget_val(getLocId(), name, value_C, val_size, H5P_DEFAULT);
if( ret_value < 0 )
- {
throwException("getLinkval", "H5Lget_val failed");
- }
+
value = H5std_string(value_C);
delete []value_C;
}
@@ -498,9 +483,7 @@ void CommonFG::setComment( const char* name, const char* comment ) const
{
herr_t ret_value = H5Oset_comment_by_name( getLocId(), name, comment, H5P_DEFAULT );
if( ret_value < 0 )
- {
throwException("setComment", "H5Oset_comment_by_name failed");
- }
}
//--------------------------------------------------------------------------
@@ -530,9 +513,7 @@ void CommonFG::removeComment(const char* name) const
{
herr_t ret_value = H5Oset_comment_by_name(getLocId(), name, NULL, H5P_DEFAULT);
if( ret_value < 0 )
- {
throwException("removeComment", "H5Oset_comment_by_name failed");
- }
}
//--------------------------------------------------------------------------
@@ -588,9 +569,8 @@ H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const
// if H5Oget_comment_by_name returns SUCCEED, return the string comment,
// otherwise, throw an exception
if( ret_value < 0 )
- {
throwException("getComment", "H5Oget_comment_by_name failed");
- }
+
H5std_string comment = H5std_string(comment_C);
delete []comment_C;
return (comment);
@@ -628,9 +608,7 @@ void CommonFG::mount( const char* name, H5File& child, PropList& plist ) const
// Raise exception if H5Fmount returns negative value
if( ret_value < 0 )
- {
throwException("mount", "H5Fmount failed");
- }
}
//--------------------------------------------------------------------------
@@ -659,9 +637,7 @@ void CommonFG::unmount( const char* name ) const
// Raise exception if H5Funmount returns negative value
if( ret_value < 0 )
- {
throwException("unmount", "H5Funmount failed");
- }
}
//--------------------------------------------------------------------------
@@ -1006,9 +982,7 @@ hsize_t CommonFG::getNumObjs() const
herr_t ret_value = H5Gget_info(getLocId(), &ginfo);
if(ret_value < 0)
- {
throwException("getNumObjs", "H5Gget_info failed");
- }
return (ginfo.nlinks);
}
@@ -1032,9 +1006,7 @@ H5std_string CommonFG::getObjnameByIdx(hsize_t idx) const
// call H5Lget_name_by_idx with name as NULL to get its length
ssize_t name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, NULL, 0, H5P_DEFAULT);
if(name_len < 0)
- {
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
- }
// now, allocate C buffer to get the name
char* name_C = new char[name_len+1];
@@ -1067,9 +1039,8 @@ ssize_t CommonFG::getObjnameByIdx(hsize_t idx, char* name, size_t size) const
{
ssize_t name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name, size, H5P_DEFAULT);
if(name_len < 0)
- {
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
- }
+
return (name_len);
}
@@ -1085,9 +1056,8 @@ ssize_t CommonFG::getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size)
char* name_C = new char[size];
ssize_t name_len = getObjnameByIdx(idx, name_C, size);
if(name_len < 0)
- {
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
- }
+
name = H5std_string(name_C);
delete []name_C;
return (name_len);
@@ -1107,9 +1077,8 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx) const
{
H5G_obj_t obj_type = H5Gget_objtype_by_idx(getLocId(), idx);
if (obj_type == H5G_UNKNOWN)
- {
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
- }
+
return (obj_type);
}
@@ -1135,9 +1104,7 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, char* type_name) const
case H5G_TYPE: HDstrcpy(type_name, "datatype"); break;
case H5G_UNKNOWN:
default:
- {
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
- }
}
return (obj_type);
}
@@ -1163,9 +1130,7 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, H5std_string& type_name) const
case H5G_TYPE: type_name = H5std_string("datatype"); break;
case H5G_UNKNOWN:
default:
- {
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
- }
}
return (obj_type);
}