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 /hl/fortran | |
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 'hl/fortran')
-rwxr-xr-x | hl/fortran/src/H5IMfc.c | 39 | ||||
-rwxr-xr-x | hl/fortran/src/H5TBfc.c | 639 |
2 files changed, 243 insertions, 435 deletions
diff --git a/hl/fortran/src/H5IMfc.c b/hl/fortran/src/H5IMfc.c index bbf98cf..7a54437 100755 --- a/hl/fortran/src/H5IMfc.c +++ b/hl/fortran/src/H5IMfc.c @@ -17,7 +17,7 @@ #include "H5IMcc.h" #include "H5LTf90proto.h" - +#include "H5Eprivate.h" /*------------------------------------------------------------------------- * Function: h5immake_image_8bit_c @@ -377,49 +377,30 @@ nh5immake_palette_c (hid_t_f *loc_id, hsize_t_f *dims, void *buf) { - int ret_value = -1; - herr_t ret; - hid_t c_loc_id; char *c_name = NULL; - int c_namelen; - hsize_t *c_dims; + hsize_t c_dims[H5S_MAX_RANK]; int i; int rank=2; + int_f ret_value = 0; /* * convert FORTRAN name to C name */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - c_dims = malloc(sizeof(hsize_t) * (rank )); - if (c_dims == NULL) - goto done; + if(NULL == (c_name = (char *)HD5f2cstring(name, (int)*namelen))) + HGOTO_DONE(FAIL) - for (i = 0; i < rank ; i++) - { + for(i = 0; i < rank ; i++) c_dims[i] = dims[i]; - } /* * call H5IMmake_palette function. */ - c_loc_id = (hid_t)*loc_id; - - ret = H5IMmake_palettef(c_loc_id,c_name,c_dims,buf); - - if (ret < 0) - goto done; - - ret_value = 0; + if(H5IMmake_palettef((hid_t)*loc_id, c_name, c_dims, buf) < 0) + HGOTO_DONE(FAIL) done: - if(c_name!=NULL) - free(c_name); - if(c_dims!=NULL) - free(c_dims); + if(c_name) + HDfree(c_name); return ret_value; } diff --git a/hl/fortran/src/H5TBfc.c b/hl/fortran/src/H5TBfc.c index 38af99c..a09d73b 100755 --- a/hl/fortran/src/H5TBfc.c +++ b/hl/fortran/src/H5TBfc.c @@ -17,6 +17,7 @@ #include "H5TBprivate.h" #include "H5LTf90proto.h" +#include "H5Eprivate.h" /*------------------------------------------------------------------------- * Function: h5tbmake_table_c @@ -52,134 +53,99 @@ nh5tbmake_table_c(int_f *namelen1, int_f *namelen2, /* field_names lenghts */ _fcd field_names) /* field_names */ { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; - char *c_name1 = NULL; - int c_namelen1; + char *c_name = NULL; + char *c_name1 = NULL; hsize_t num_elem; hsize_t i; - int max_len=1; - hid_t c_loc_id = *loc_id; - hsize_t c_nfields = *nfields; - hsize_t c_nrecords = *nrecords; + int max_len = 1; + hid_t c_loc_id = *loc_id; + hsize_t c_nfields = *nfields; + hsize_t c_nrecords = *nrecords; hsize_t c_chunk_size = *chunk_size; - size_t c_type_size = *type_size; - size_t *c_field_offset = NULL; - hid_t *c_field_types = NULL; - char **c_field_names = NULL; - char *tmp = NULL, *tmp_p = NULL; + size_t c_type_size = *type_size; + size_t *c_field_offset = NULL; + hid_t *c_field_types = NULL; + char **c_field_names = NULL; + char *tmp = NULL, *tmp_p; + int_f ret_value = 0; num_elem = *nfields; - - for ( i = 0; i < num_elem; i++) - { - if (namelen2[i] > max_len) max_len = namelen2[i]; + for(i = 0; i < num_elem; i++) { + if(namelen2[i] > max_len) + max_len = namelen2[i]; } /* - * convert FORTRAN name to C name - */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - c_namelen1 = *namelen1; - c_name1 = (char *)HD5f2cstring(name1, c_namelen1); - if (c_name1 == NULL) - goto done; - - c_field_offset = (size_t*)malloc(sizeof(size_t) * (size_t)c_nfields); - if (!c_field_offset) - goto done; - - c_field_types = (hid_t*)malloc(sizeof(hid_t) * (size_t)c_nfields); - if (!c_field_types) - goto done; - - for ( i = 0; i < num_elem; i++) - { + * convert FORTRAN name to C name + */ + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) + if(NULL == (c_name1 = (char *)HD5f2cstring(name1, (size_t)*namelen1))) + HGOTO_DONE(FAIL) + if(NULL == (c_field_offset = (size_t *)HDmalloc(sizeof(size_t) * (size_t)c_nfields))) + HGOTO_DONE(FAIL) + if(NULL == (c_field_types = (hid_t *)HDmalloc(sizeof(hid_t) * (size_t)c_nfields))) + HGOTO_DONE(FAIL) + + for (i = 0; i < num_elem; i++) { c_field_offset[i] = field_offset[i]; - c_field_types[i] = field_types[i]; + c_field_types[i] = field_types[i]; } /* - * allocate array of character pointers - */ - c_field_names = (char **)malloc((size_t)num_elem * sizeof(char *)); - if (c_field_names == NULL) - goto done; + * allocate array of character pointers + */ + if(NULL == (c_field_names = (char **)HDcalloc((size_t)num_elem, sizeof(char *)))) + HGOTO_DONE(FAIL) /* copy data to long C string */ - tmp = (char *)HD5f2cstring(field_names, (int)(max_len*num_elem)); - if (tmp == NULL) - { - goto done; - } + if(NULL == (tmp = (char *)HD5f2cstring(field_names, (size_t)(max_len * num_elem)))) + HGOTO_DONE(FAIL) /* - * move data from temorary buffer - */ + * move data from temorary buffer + */ tmp_p = tmp; - for (i=0; i < num_elem; i++) - { - c_field_names[i] = (char *) malloc((size_t)namelen2[i]+1); - memcpy(c_field_names[i], tmp_p, (size_t)namelen2[i]); + for(i = 0; i < num_elem; i++) { + if(NULL == (c_field_names[i] = (char *)HDmalloc((size_t)namelen2[i] + 1))) + HGOTO_DONE(FAIL) + + HDmemcpy(c_field_names[i], tmp_p, (size_t)namelen2[i]); c_field_names[i][namelen2[i]] = '\0'; tmp_p = tmp_p + max_len; - } + } /* end for */ /* - * call H5TBmake_table function. - */ - - ret = H5TBmake_table(c_name1, - c_loc_id, - c_name, - c_nfields, - c_nrecords, - c_type_size, - c_field_names, - c_field_offset, - c_field_types, - c_chunk_size, - NULL, - *compress, - NULL); - - if (ret < 0) - goto done; - - ret_value = 0; - -done: - if(c_name != NULL) - free(c_name); - if(c_name1 != NULL) - free(c_name1); - - for ( i = 0; i < num_elem; i++) - { - if ( c_field_names[i] ) - free (c_field_names[i]); - } - if ( c_field_names ) - free(c_field_names); - if ( tmp ) - free(tmp); - if ( c_field_offset ) - free(c_field_offset); - if ( c_field_types ) - free(c_field_types); + * call H5TBmake_table function. + */ + if(H5TBmake_table(c_name1, c_loc_id, c_name, c_nfields, c_nrecords, + c_type_size, c_field_names, c_field_offset, c_field_types, + c_chunk_size, NULL, *compress, NULL) < 0) + HGOTO_DONE(FAIL) + +done: + if(c_name) + HDfree(c_name); + if(c_name1) + HDfree(c_name1); + if(c_field_names) { + for(i = 0; i < num_elem; i++) { + if(c_field_names[i]) + HDfree(c_field_names[i]); + } + HDfree(c_field_names); + } /* end if */ + if(tmp) + HDfree(tmp); + if(c_field_offset) + HDfree(c_field_offset); + if(c_field_types) + HDfree(c_field_types); return ret_value; } - - /*------------------------------------------------------------------------- * Function: h5tbwrite_field_name_c * @@ -210,59 +176,34 @@ nh5tbwrite_field_name_c(hid_t_f *loc_id, size_t_f *type_size, void *buf) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; - char *c_name1 = NULL; - int c_namelen1; + char *c_name = NULL; + char *c_name1 = NULL; hid_t c_loc_id = *loc_id; hsize_t c_start = *start; hsize_t c_nrecords = *nrecords; size_t c_type_size = *type_size; - size_t c_type_sizes[1]; - - c_type_sizes[0] = c_type_size; - + int_f ret_value = 0; /* * convert FORTRAN name to C name */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - c_namelen1 = *namelen1; - c_name1 = (char *)HD5f2cstring(field_name, c_namelen1); - if (c_name1 == NULL) - goto done; + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) + if(NULL == (c_name1 = (char *)HD5f2cstring(field_name, (size_t)*namelen1))) + HGOTO_DONE(FAIL) /* * call H5TBwrite_fields_name function. */ - - ret = H5TBwrite_fields_name(c_loc_id, - c_name, - c_name1, - c_start, - c_nrecords, - c_type_size, - 0, - c_type_sizes, - buf); - - if (ret < 0) - goto done; - - ret_value = 0; - + if(H5TBwrite_fields_name(c_loc_id, c_name, c_name1, c_start, c_nrecords, + c_type_size, 0, &c_type_size, buf) < 0) + HGOTO_DONE(FAIL) done: - if(c_name != NULL) - free(c_name); - if(c_name1 != NULL) - free(c_name1); + if(c_name) + HDfree(c_name); + if(c_name1) + HDfree(c_name1); return ret_value; } @@ -293,6 +234,7 @@ nh5tbwrite_field_name_fl_c(hid_t_f *loc_id, { return nh5tbwrite_field_name_c(loc_id,namelen,name,namelen1,field_name,start,nrecords,type_size,buf); } + int_f nh5tbwrite_field_name_dl_c(hid_t_f *loc_id, int_f *namelen, @@ -306,6 +248,7 @@ nh5tbwrite_field_name_dl_c(hid_t_f *loc_id, { return nh5tbwrite_field_name_c(loc_id,namelen,name,namelen1,field_name,start,nrecords,type_size,buf); } + int_f nh5tbwrite_field_name_st_c(hid_t_f *loc_id, int_f *namelen, @@ -319,6 +262,7 @@ nh5tbwrite_field_name_st_c(hid_t_f *loc_id, { return nh5tbwrite_field_name_c(loc_id,namelen,name,namelen1,field_name,start,nrecords,type_size,buf); } + /*------------------------------------------------------------------------- * Function: h5tbread_field_name_c * @@ -349,57 +293,34 @@ nh5tbread_field_name_c(hid_t_f *loc_id, size_t_f *type_size, void *buf) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; - char *c_name1 = NULL; - int c_namelen1; + char *c_name = NULL; + char *c_name1 = NULL; hid_t c_loc_id = *loc_id; hsize_t c_start = *start; hsize_t c_nrecords = *nrecords; size_t c_type_size = *type_size; - size_t c_type_sizes[1]; - - c_type_sizes[0] = c_type_size; - + int_f ret_value = 0; /* * convert FORTRAN name to C name */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - c_namelen1 = *namelen1; - c_name1 = (char *)HD5f2cstring(field_name, c_namelen1); - if (c_name1 == NULL) - goto done; + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) + if(NULL == (c_name1 = (char *)HD5f2cstring(field_name, (size_t)*namelen1))) + HGOTO_DONE(FAIL) /* * call H5TBread_fields_name function. */ - - ret = H5TBread_fields_name(c_loc_id, - c_name, - c_name1, - c_start, - c_nrecords, - c_type_size, - 0, - c_type_sizes, - buf); - - if (ret < 0) - goto done; - - ret_value = 0; - + if(H5TBread_fields_name(c_loc_id, c_name, c_name1, c_start, c_nrecords, + c_type_size, 0, &c_type_size, buf) < 0) + HGOTO_DONE(FAIL) done: - if(c_name != NULL) - free(c_name); + if(c_name) + HDfree(c_name); + if(c_name1) + HDfree(c_name1); return ret_value; } @@ -417,6 +338,7 @@ nh5tbread_field_name_int_c(hid_t_f *loc_id, { return nh5tbread_field_name_c(loc_id,namelen,name,namelen1,field_name,start,nrecords,type_size,buf); } + int_f nh5tbread_field_name_fl_c(hid_t_f *loc_id, int_f *namelen, @@ -430,6 +352,7 @@ nh5tbread_field_name_fl_c(hid_t_f *loc_id, { return nh5tbread_field_name_c(loc_id,namelen,name,namelen1,field_name,start,nrecords,type_size,buf); } + int_f nh5tbread_field_name_dl_c(hid_t_f *loc_id, int_f *namelen, @@ -443,6 +366,7 @@ nh5tbread_field_name_dl_c(hid_t_f *loc_id, { return nh5tbread_field_name_c(loc_id,namelen,name,namelen1,field_name,start,nrecords,type_size,buf); } + int_f nh5tbread_field_name_st_c(hid_t_f *loc_id, int_f *namelen, @@ -486,45 +410,31 @@ nh5tbwrite_field_index_c(hid_t_f *loc_id, size_t_f *type_size, void *buf) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; + char *c_name = NULL; hid_t c_loc_id = *loc_id; hsize_t c_start = *start; hsize_t c_nrecords = *nrecords; size_t c_type_size = *type_size; - size_t c_type_sizes[1]; - int c_field_index[1]; - - c_type_sizes[0] = c_type_size; - c_field_index[0] = *field_index - 1; /* C zero based index */ - + int c_field_index = *field_index - 1; /* C zero based index */ + int_f ret_value = 0; /* * convert FORTRAN name to C name */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) /* * call H5TBwrite_fields_name function. */ - - ret = H5TBwrite_fields_index(c_loc_id,c_name,(hsize_t)1,c_field_index,c_start,c_nrecords,c_type_size, - 0,c_type_sizes,buf); - - if (ret < 0) - goto done; - - ret_value = 0; + if(H5TBwrite_fields_index(c_loc_id, c_name, (hsize_t)1, &c_field_index, + c_start, c_nrecords, c_type_size, 0, &c_type_size, buf) < 0) + HGOTO_DONE(FAIL) done: - if(c_name != NULL) - free(c_name); + if(c_name) + HDfree(c_name); return ret_value; } @@ -541,6 +451,7 @@ nh5tbwrite_field_index_int_c(hid_t_f *loc_id, { return nh5tbwrite_field_index_c(loc_id,namelen,name,field_index,start,nrecords,type_size,buf); } + int_f nh5tbwrite_field_index_fl_c(hid_t_f *loc_id, int_f *namelen, @@ -553,6 +464,7 @@ nh5tbwrite_field_index_fl_c(hid_t_f *loc_id, { return nh5tbwrite_field_index_c(loc_id,namelen,name,field_index,start,nrecords,type_size,buf); } + int_f nh5tbwrite_field_index_dl_c(hid_t_f *loc_id, int_f *namelen, @@ -565,6 +477,7 @@ nh5tbwrite_field_index_dl_c(hid_t_f *loc_id, { return nh5tbwrite_field_index_c(loc_id,namelen,name,field_index,start,nrecords,type_size,buf); } + int_f nh5tbwrite_field_index_st_c(hid_t_f *loc_id, int_f *namelen, @@ -607,51 +520,30 @@ nh5tbread_field_index_c(hid_t_f *loc_id, size_t_f *type_size, void *buf) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; + char *c_name = NULL; hid_t c_loc_id = *loc_id; hsize_t c_start = *start; hsize_t c_nrecords = *nrecords; size_t c_type_size = *type_size; - size_t c_type_sizes[1]; - int c_field_index[1]; - - c_type_sizes[0] = c_type_size; - c_field_index[0] = *field_index - 1; /* C zero based index */ - + int c_field_index = *field_index - 1; /* C zero based index */ + int_f ret_value = 0; /* - * convert FORTRAN name to C name - */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; + * convert FORTRAN name to C name + */ + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) /* - * call H5TBread_fields_index function. - */ - - ret = H5TBread_fields_index(c_loc_id, - c_name,(hsize_t)1, - c_field_index, - c_start, - c_nrecords, - c_type_size, - 0, - c_type_sizes, - buf); - - if (ret < 0) - goto done; - - ret_value = 0; + * call H5TBread_fields_index function. + */ + if(H5TBread_fields_index(c_loc_id, c_name,(hsize_t)1, &c_field_index, + c_start, c_nrecords, c_type_size, 0, &c_type_size, buf) < 0) + HGOTO_DONE(FAIL) done: - if(c_name != NULL) - free(c_name); + if(c_name) + HDfree(c_name); return ret_value; } @@ -668,6 +560,7 @@ nh5tbread_field_index_int_c(hid_t_f *loc_id, { return nh5tbread_field_index_c(loc_id,namelen,name,field_index,start,nrecords,type_size,buf); } + int_f nh5tbread_field_index_fl_c(hid_t_f *loc_id, int_f *namelen, @@ -680,6 +573,7 @@ nh5tbread_field_index_fl_c(hid_t_f *loc_id, { return nh5tbread_field_index_c(loc_id,namelen,name,field_index,start,nrecords,type_size,buf); } + int_f nh5tbread_field_index_dl_c(hid_t_f *loc_id, int_f *namelen, @@ -692,6 +586,7 @@ nh5tbread_field_index_dl_c(hid_t_f *loc_id, { return nh5tbread_field_index_c(loc_id,namelen,name,field_index,start,nrecords,type_size,buf); } + int_f nh5tbread_field_index_st_c(hid_t_f *loc_id, int_f *namelen, @@ -734,51 +629,34 @@ nh5tbinsert_field_c(hid_t_f *loc_id, int_f *position, void *buf) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; - char *c_name1 = NULL; - int c_namelen1; + char *c_name = NULL; + char *c_name1 = NULL; hid_t c_loc_id = *loc_id; hid_t c_field_type = *field_type; hsize_t c_position = *position; + int_f ret_value = 0; /* * convert FORTRAN name to C name */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - c_namelen1 = *namelen1; - c_name1 = (char *)HD5f2cstring(field_name, c_namelen1); - if (c_name1 == NULL) - goto done; + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) + if(NULL == (c_name1 = (char *)HD5f2cstring(field_name, (size_t)*namelen1))) + HGOTO_DONE(FAIL) /* * call H5TBinsert_field function. */ - ret = H5TBinsert_field(c_loc_id, - c_name, - c_name1, - c_field_type, - c_position, - NULL, - buf); - - if (ret < 0) - goto done; - - ret_value = 0; + if(H5TBinsert_field(c_loc_id, c_name, c_name1, c_field_type, c_position, + NULL, buf) < 0) + HGOTO_DONE(FAIL) done: - if(c_name != NULL) - free(c_name); - if(c_name1 != NULL) - free(c_name1); + if(c_name ) + HDfree(c_name); + if(c_name1) + HDfree(c_name1); return ret_value; } @@ -795,6 +673,7 @@ nh5tbinsert_field_int_c(hid_t_f *loc_id, { return nh5tbinsert_field_c(loc_id,namelen,name,namelen1,field_name,field_type,position,buf); } + int_f nh5tbinsert_field_fl_c(hid_t_f *loc_id, int_f *namelen, @@ -807,6 +686,7 @@ nh5tbinsert_field_fl_c(hid_t_f *loc_id, { return nh5tbinsert_field_c(loc_id,namelen,name,namelen1,field_name,field_type,position,buf); } + int_f nh5tbinsert_field_dl_c(hid_t_f *loc_id, int_f *namelen, @@ -819,6 +699,7 @@ nh5tbinsert_field_dl_c(hid_t_f *loc_id, { return nh5tbinsert_field_c(loc_id,namelen,name,namelen1,field_name,field_type,position,buf); } + int_f nh5tbinsert_field_st_c(hid_t_f *loc_id, int_f *namelen, @@ -858,49 +739,32 @@ nh5tbdelete_field_c(hid_t_f *loc_id, int_f *namelen1, _fcd field_name) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; - char *c_name1 = NULL; - int c_namelen1; + char *c_name = NULL; + char *c_name1 = NULL; hid_t c_loc_id = *loc_id; + int_f ret_value = 0; /* - * convert FORTRAN name to C name - */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - c_namelen1 = *namelen1; - c_name1 = (char *)HD5f2cstring(field_name, c_namelen1); - if (c_name1 == NULL) - goto done; + * convert FORTRAN name to C name + */ + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) + if(NULL == (c_name1 = (char *)HD5f2cstring(field_name, (size_t)*namelen1))) + HGOTO_DONE(FAIL) /* - * call H5TBinsert_field function. - */ - - ret = H5TBdelete_field(c_loc_id, - c_name, - c_name1); - - if (ret < 0) - goto done; - - ret_value = 0; + * call H5TBinsert_field function. + */ + if(H5TBdelete_field(c_loc_id, c_name, c_name1) < 0) + HGOTO_DONE(FAIL) done: - if(c_name != NULL) - free(c_name); + if(c_name) + HDfree(c_name); return ret_value; } - - /*------------------------------------------------------------------------- * Function: h5tbget_table_info_c * @@ -927,42 +791,30 @@ nh5tbget_table_info_c(hid_t_f *loc_id, hsize_t_f *nfields, hsize_t_f *nrecords) { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; + char *c_name = NULL; hid_t c_loc_id = *loc_id; hsize_t c_nfields; hsize_t c_nrecords; + int_f ret_value = 0; /* - * convert FORTRAN name to C name - */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; + * convert FORTRAN name to C name + */ + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) /* - * call H5TBread_fields_index function. - */ - - ret = H5TBget_table_info(c_loc_id, - c_name, - &c_nfields, - &c_nrecords); - - if (ret < 0) - goto done; + * call H5TBread_fields_index function. + */ + if(H5TBget_table_info(c_loc_id, c_name, &c_nfields, &c_nrecords) < 0) + HGOTO_DONE(FAIL) *nfields = (hsize_t_f) c_nfields;; *nrecords = (hsize_t_f) c_nrecords; - ret_value = 0; - done: - if(c_name != NULL) - free(c_name); + if(c_name) + HDfree(c_name); return ret_value; } @@ -999,113 +851,88 @@ nh5tbget_field_info_c(hid_t_f *loc_id, _fcd field_names) /* field_names */ { - int ret_value = -1; - herr_t ret; - char *c_name = NULL; - int c_namelen; + char *c_name = NULL; hsize_t num_elem; hsize_t i; - int max_len=1; + int max_len = 1; hid_t c_loc_id = *loc_id; hsize_t c_nfields = *nfields; - size_t *c_field_sizes = NULL; - size_t *c_field_offsets = NULL; + size_t *c_field_sizes = NULL; + size_t *c_field_offsets = NULL; size_t c_type_size; - char **c_field_names = NULL; - char *tmp = NULL, *tmp_p = NULL; - int c_lenmax=HLTB_MAX_FIELD_LEN; - size_t length = 0; + char **c_field_names = NULL; + char *tmp = NULL, *tmp_p; + int c_lenmax = HLTB_MAX_FIELD_LEN; + int_f ret_value = 0; num_elem = c_nfields; - - for (i=0; i < num_elem; i++) - { - if (namelen2[i] > max_len) max_len = namelen2[i]; + for(i = 0; i < num_elem; i++) { + if(namelen2[i] > max_len) + max_len = namelen2[i]; } /* - * convert FORTRAN name to C name - */ - c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); - if (c_name == NULL) - goto done; - - - c_field_offsets = (size_t*)malloc(sizeof(size_t) * (size_t)c_nfields); - if (!c_field_offsets) - goto done; - - c_field_sizes = (size_t*)malloc(sizeof(size_t) * (size_t)c_nfields); - if (!c_field_sizes) - goto done; - - c_field_names = malloc( sizeof(char*) * (size_t)c_nfields ); - if (!c_field_names) return ret_value; - for ( i = 0; i < c_nfields; i++) - { - c_field_names[i] = malloc( sizeof(char) * HLTB_MAX_FIELD_LEN ); - } + * convert FORTRAN name to C name + */ + if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) + HGOTO_DONE(FAIL) + if(NULL == (c_field_offsets = (size_t *)HDmalloc(sizeof(size_t) * (size_t)c_nfields))) + HGOTO_DONE(FAIL) + if(NULL == (c_field_sizes = (size_t *)HDmalloc(sizeof(size_t) * (size_t)c_nfields))) + HGOTO_DONE(FAIL) + if(NULL == (c_field_names = (char **)HDcalloc((size_t)c_nfields, sizeof(char *)))) + HGOTO_DONE(FAIL) + + for(i = 0; i < c_nfields; i++) + if(NULL == (c_field_names[i] = (char *)HDmalloc(sizeof(char) * HLTB_MAX_FIELD_LEN))) + HGOTO_DONE(FAIL) /* - * call H5TBget_field_info function. - */ - - ret = H5TBget_field_info(c_loc_id, - c_name, - c_field_names, - c_field_sizes, - c_field_offsets, - &c_type_size); + * call H5TBget_field_info function. + */ + if(H5TBget_field_info(c_loc_id, c_name, c_field_names, c_field_sizes, + c_field_offsets, &c_type_size) < 0) + HGOTO_DONE(FAIL) /* return values*/ /* names array */ - tmp = (char *)malloc(c_lenmax* (size_t) c_nfields + 1); + if(NULL == (tmp = (char *)HDmalloc((c_lenmax * (size_t)c_nfields) + 1))) + HGOTO_DONE(FAIL) + tmp_p = tmp; - memset(tmp,' ', c_lenmax* (size_t) c_nfields); - tmp[c_lenmax*c_nfields] = '\0'; - for (i=0; i < c_nfields; i++) - { - memcpy(tmp_p, c_field_names[i], strlen(c_field_names[i])); - namelen2[i] = (int_f)strlen(c_field_names[i]); - length = MAX(length, strlen(c_field_names[i])); - tmp_p = tmp_p + c_lenmax; + HDmemset(tmp, ' ', c_lenmax * (size_t)c_nfields); + tmp[c_lenmax * c_nfields] = '\0'; + for(i = 0; i < c_nfields; i++) { + size_t field_name_len = HDstrlen(c_field_names[i]); + + HDmemcpy(tmp_p, c_field_names[i], field_name_len); + namelen2[i] = (int_f)field_name_len; + tmp_p += c_lenmax; } - HD5packFstring(tmp, _fcdtocp(field_names), (int)(c_lenmax*c_nfields)); - + HD5packFstring(tmp, _fcdtocp(field_names), (int)(c_lenmax * c_nfields)); *type_size = (size_t_f)c_type_size; - for (i=0; i < num_elem; i++) - { + for(i = 0; i < num_elem; i++) { field_sizes[i] = (size_t_f)c_field_sizes[i]; field_offsets[i] = (size_t_f)c_field_offsets[i]; } - - if (ret < 0) - goto done; - - ret_value = 0; - - done: - if(c_name != NULL) - free(c_name); - - for ( i = 0; i < num_elem; i++) - { - if ( c_field_names[i] ) - free (c_field_names[i]); - } - if ( c_field_names ) - free(c_field_names); - if ( tmp ) - free(tmp); - if ( c_field_offsets ) - free(c_field_offsets); - if ( c_field_sizes ) - free(c_field_sizes); + if(c_name) + HDfree(c_name); + if(c_field_names) { + for(i = 0; i < num_elem; i++) + if(c_field_names[i]) + HDfree(c_field_names[i]); + HDfree(c_field_names); + } /* end if */ + if(tmp) + HDfree(tmp); + if(c_field_offsets) + HDfree(c_field_offsets); + if(c_field_sizes) + HDfree(c_field_sizes); return ret_value; } |