diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 04:39:40 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 04:39:40 (GMT) |
commit | fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0 (patch) | |
tree | a18fedef2b670c044913622650ef581dedce7ee1 /fortran/src/H5Pf.c | |
parent | 2c872f398b3824c416d42f2018c3d3ea0c40e80f (diff) | |
download | hdf5-fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0.zip hdf5-fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0.tar.gz hdf5-fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0.tar.bz2 |
[svn-r18157] Description:
Bring back changes from Coverity session on 1/15/10:
r18111:
Fix Coverity issue #130: make certain that the cache gets freed on error.
r18112:
Fix Coverity issue #43 by making cache testing calls protected by 'pass'
variable.
r18113:
Fix Coverity issue #129 by releasing the cache on error.
r18115:
Coverity #45 fix: patched an error check in H5Screate_simple to prevent future dereferencing of a NULL point.
Added a verification in test/th5s.c.
r18116:
Fix Coverity issue #43 by releasing cache on error.
r18117:
Coverity #362,363 by adding HGOTO_DONE, freeing allocations and associated changes. REsolving coverity results #364-368, 369, 370-372, 377, 379, and 380.
r18118:
Fix Coverity issue #42: assert that cache & test specification pointer are
valid.
r18122:
Coverity #362,363 by adding HGOTO_DONE and freeing allocations. This also takes care of #357,358.
r18123:
Coverity #359-361, 373-376: Added HGOTO_DONE(FAIL) statement after checking allocation for NULL. Verified allocation is freed in done block.
r18128:
Fixed coverity issue #10 -- removed dead code.
Tested on:
Mac OS X/32 10.6.2 (amazon)
Diffstat (limited to 'fortran/src/H5Pf.c')
-rw-r--r-- | fortran/src/H5Pf.c | 155 |
1 files changed, 83 insertions, 72 deletions
diff --git a/fortran/src/H5Pf.c b/fortran/src/H5Pf.c index 0929d7a..ee2145d 100644 --- a/fortran/src/H5Pf.c +++ b/fortran/src/H5Pf.c @@ -17,6 +17,7 @@ /* This files contains C stubs for H5P Fortran APIs */ #include "H5f90.h" +#include "H5Eprivate.h" /*---------------------------------------------------------------------------- * Name: h5pcreate_c @@ -32,16 +33,17 @@ int_f nh5pcreate_c ( hid_t_f *class, hid_t_f *prp_id ) { - hid_t c_class; - int ret_value = 0; - hid_t c_prp_id; + hid_t c_prp_id; + int_f ret_value = 0; - c_class = (hid_t)*class; - c_prp_id = H5Pcreate(c_class); + c_prp_id = H5Pcreate((hid_t)*class); + if(c_prp_id < 0) + HGOTO_DONE(FAIL) - if ( c_prp_id < 0 ) ret_value = -1; - *prp_id = (hid_t_f)c_prp_id; - return ret_value; + *prp_id = (hid_t_f)c_prp_id; + +done: + return ret_value; } /*---------------------------------------------------------------------------- @@ -57,11 +59,12 @@ nh5pcreate_c ( hid_t_f *class, hid_t_f *prp_id ) int_f nh5pclose_c ( hid_t_f *prp_id ) { - int ret_value = 0; - hid_t c_prp_id=(*prp_id); + int_f ret_value = 0; - if ( H5Pclose(c_prp_id) < 0 ) ret_value = -1; - return ret_value; + if(H5Pclose((hid_t)*prp_id) < 0) + ret_value = -1; + + return ret_value; } @@ -79,15 +82,17 @@ nh5pclose_c ( hid_t_f *prp_id ) int_f nh5pcopy_c ( hid_t_f *prp_id , hid_t_f *new_prp_id) { - int ret_value = 0; - hid_t c_prp_id; - hid_t c_new_prp_id; + hid_t c_new_prp_id; + int_f ret_value = 0; - c_prp_id = *prp_id; - c_new_prp_id = H5Pcopy(c_prp_id); - if ( c_new_prp_id < 0 ) ret_value = -1; - *new_prp_id = (hid_t_f)c_new_prp_id; - return ret_value; + c_new_prp_id = H5Pcopy((hid_t)*prp_id); + if(c_new_prp_id < 0) + HGOTO_DONE(FAIL) + + *new_prp_id = (hid_t_f)c_new_prp_id; + +done: + return ret_value; } /*---------------------------------------------------------------------------- @@ -105,17 +110,17 @@ nh5pcopy_c ( hid_t_f *prp_id , hid_t_f *new_prp_id) int_f nh5pequal_c ( hid_t_f *plist1_id , hid_t_f *plist2_id, int_f * c_flag) { - int ret_value = 0; - hid_t c_plist1_id; - hid_t c_plist2_id; - htri_t c_c_flag; - - c_plist1_id = (hid_t)*plist1_id; - c_plist2_id = (hid_t)*plist2_id; - c_c_flag = H5Pequal(c_plist1_id, c_plist2_id); - if ( c_c_flag < 0 ) ret_value = -1; - *c_flag = (int_f)c_c_flag; - return ret_value; + htri_t c_c_flag; + int_f ret_value = 0; + + c_c_flag = H5Pequal((hid_t)*plist1_id, (hid_t)*plist2_id); + if(c_c_flag < 0) + HGOTO_DONE(FAIL) + + *c_flag = (int_f)c_c_flag; + +done: + return ret_value; } @@ -139,20 +144,19 @@ nh5pequal_c ( hid_t_f *plist1_id , hid_t_f *plist2_id, int_f * c_flag) int_f nh5pget_class_c ( hid_t_f *prp_id , int_f *classtype) { - int ret_value = 0; - hid_t c_prp_id; - hid_t c_classtype; + hid_t c_classtype; + int_f ret_value = 0; - c_prp_id = *prp_id; - c_classtype = H5Pget_class(c_prp_id); - if (c_classtype == H5P_ROOT ) { + c_classtype = H5Pget_class((hid_t)*prp_id); + if(c_classtype == H5P_ROOT) { *classtype = H5P_ROOT; - ret_value = -1; - return ret_value; - } - *classtype = (int_f)c_classtype; + HGOTO_DONE(FAIL) + } - return ret_value; + *classtype = (int_f)c_classtype; + +done: + return ret_value; } /*---------------------------------------------------------------------------- @@ -3962,33 +3966,39 @@ nh5pget_copy_object_c(hid_t_f *ocp_plist_id, int_f *copy_options) int_f nh5pget_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_len, size_t_f *size) { - int_f ret_value = -1; - char *c_expression = NULL; /* Buffer to hold C string */ - size_t c_expression_len; - ssize_t ret; + char *c_expression = NULL; /* Buffer to hold C string */ + size_t c_expression_len; + ssize_t ret; + int_f ret_value = 0; + c_expression_len = (size_t)*expression_len + 1; - c_expression_len = (size_t)*expression_len + 1; + /* + * Allocate memory to store the expression. + */ + if(c_expression_len) { + c_expression = (char*)HDmalloc(c_expression_len); + if(NULL == c_expression) + HGOTO_DONE(FAIL) + } /* end if */ - /* should expression_len be size_t_f? */ - /* - * Allocate memory to store the expression. - */ - if( c_expression_len) c_expression = (char*) HDmalloc(c_expression_len); - if (c_expression == NULL) return ret_value; + /* + * Call H5Pget_data_transform function. + */ + ret = H5Pget_data_transform((hid_t)*plist_id, c_expression, c_expression_len); + if(ret < 0) + HGOTO_DONE(FAIL) - /* - * Call h5pget_data_transform function. - */ - ret = H5Pget_data_transform((hid_t)*plist_id, c_expression, c_expression_len); - if(ret < 0) return ret_value; - /* or strlen ? */ - HD5packFstring(c_expression, _fcdtocp(expression), c_expression_len-1); + /* or strlen ? */ + HD5packFstring(c_expression, _fcdtocp(expression), c_expression_len - 1); - *size = (size_t_f)ret; + *size = (size_t_f)ret; - ret_value = 0; - return ret_value; +done: + if(c_expression) + HDfree(c_expression); + + return ret_value; } /*---------------------------------------------------------------------------- @@ -4012,23 +4022,24 @@ nh5pget_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_l int_f nh5pset_data_transform_c(hid_t_f *plist_id, _fcd expression, int_f *expression_len) { - int_f ret_value = -1; /* Return value */ char* c_expression = NULL; /* Buffer to hold C string */ - herr_t ret; + int_f ret_value = 0; /* Return value */ + /* * Convert FORTRAN name to C name */ if(NULL == (c_expression = HD5f2cstring(expression, (size_t)*expression_len))) - return ret_value; + HGOTO_DONE(FAIL) + /* - * Call h5pset_data_transform function. + * Call H5Pset_data_transform function. */ - ret = H5Pset_data_transform((hid_t)*plist_id, c_expression); - if(ret<0) return ret_value; + if(H5Pset_data_transform((hid_t)*plist_id, c_expression) < 0) + HGOTO_DONE(FAIL) - ret_value = 0; - if(c_expression) - HDfree(c_expression); +done: + if(c_expression) + HDfree(c_expression); return ret_value; } |