summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
commit6c9d003d4ee3bbcaf639149014e8e42ed9835621 (patch)
tree95169b1d25c154882a92b1c68d65c4bc65b04cc9 /tools
parent7f46301cee98932ecf7ad87068adc0f5d051d544 (diff)
downloadhdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.zip
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.gz
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.bz2
[svn-r18013] Description:
Bring r18011 from trunk to 1.8 branch: Bring Coverity changes into the trunk: (also other minor cleanups) r17991: Fix Coverity items 175 and 176. Fixed memory leak on error in print_enum in H5LT.c. r17993: (r17992 was not a Coverity change) Close Coverity issue #206: inconsistently checking whether dt->shared was non-NULL after H5T_alloc() returned a valid 'dt' value (which should guarantee that dt->shared is valid). r17994: Fix Coverity item 149. Fixed file handle leak on error in H5FD_stdio_open. r17995: Fixed Coverity issues 154 to 161: Added H5MP_close routine to error handling in the event *mp has not been freed before error. r17996: Close Coverity issue #126: potentially leaking merged_spans on routine failure. r17997: Fix Coverity items 147 and 148. Fixed resource leaks on error in H5FDloc.c. r17998: Coverity issue 269-272: Added integer result variable to functions that could return negative. Assigned to unsigned after checking. Added H5E_BEGIN_TRY block around H5Tclose and removed H5E_THROW in the catch block. Checked buffer is NULL before free. Changed HGOTO_ERROR outside of the if block to H5E_THROW. r17999: Close Coverity issue #127: release temporary spans in more generic manner. (Also add error checking to previous fix) r18000: Resolved Coverity issues 211 and 212 in H5T.c. Added comments to ignore Coverity warning regarding not checking pointer for NULL, as we are using an assert which catches the issue. r18001: Fix Coverity item 146. Fixed resource leak on error in H5O_layout_copy. r18002: Fix Coverity items 143 and 145. Fixed resource leaks on error in H5D_compact_copy and H5D_contig_copy. r18003: Close Coverity issue #192: close file on error r18004: Fix Coverity issue #125: release temporary spans on error r18005: Resolved Coverity issues 5, 25, and 83 (in H5T.c): Separated embedded functions in order to check for NULL on return of H5I_object before passing into H5T_copy. Check to see if new_dt is NULL within error handling before dereferencing it. Ignore Coverity's dead code warnings as the checks that lead to the code are machine dependent. r18006: Coverity 63,70,73: Checked result of function before assigning to an unsigned variable. r18007: Coverity 78,79: added continue statement if H5Pget_filter2 returns negative. r18008: Fixed Coverity issue # 138: Added support in error handling to free dst pointer (if allocated) on error. r18009: Whitespace & coding style cleanup Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production (h5committested on trunk)
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/h5dump.c39
-rw-r--r--tools/h5stat/h5stat.c10
-rw-r--r--tools/lib/h5tools.c64
-rw-r--r--tools/lib/h5tools_error.h1
4 files changed, 62 insertions, 52 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index a1f78b1..a6c1f77 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -2710,11 +2710,12 @@ dump_dcpl(hid_t dcpl_id,hid_t type_id, hid_t obj_id)
int i, next;
unsigned j;
- storage_size=H5Dget_storage_size(obj_id);
+ storage_size = H5Dget_storage_size(obj_id);
nfilters = H5Pget_nfilters(dcpl_id);
- ioffset=H5Dget_offset(obj_id);
- next=H5Pget_external_count(dcpl_id);
- strcpy(f_name,"\0");
+ ioffset = H5Dget_offset(obj_id);
+ next = H5Pget_external_count(dcpl_id);
+ HDassert(next >= 0);
+ HDstrcpy(f_name,"\0");
/*-------------------------------------------------------------------------
* STORAGE_LAYOUT
@@ -4510,14 +4511,16 @@ print_enum(hid_t type)
unsigned char *value = NULL; /*value array */
unsigned char *copy = NULL; /*a pointer to value array */
unsigned nmembs; /*number of members */
+ int snmembs;
int nchars; /*number of output characters */
hid_t super; /*enum base integer type */
hid_t native = -1; /*native integer datatype */
size_t dst_size; /*destination value type size */
unsigned i;
- nmembs = H5Tget_nmembers(type);
- assert(nmembs>0);
+ snmembs = H5Tget_nmembers(type);
+ HDassert(snmembs >= 0);
+ nmembs = (unsigned)snmembs;
super = H5Tget_super(type);
/*
@@ -4527,17 +4530,16 @@ print_enum(hid_t type)
* 2. unsigned long long -- the largest native unsigned integer
* 3. raw format
*/
- if (H5Tget_size(type) <= sizeof(long long)) {
- dst_size = sizeof(long long);
+ if(H5Tget_size(type) <= sizeof(long long)) {
+ dst_size = sizeof(long long);
- if (H5T_SGN_NONE == H5Tget_sign(type)) {
- native = H5T_NATIVE_ULLONG;
- } else {
- native = H5T_NATIVE_LLONG;
- }
- } else {
- dst_size = H5Tget_size(type);
- }
+ if(H5T_SGN_NONE == H5Tget_sign(type))
+ native = H5T_NATIVE_ULLONG;
+ else
+ native = H5T_NATIVE_LLONG;
+ } /* end if */
+ else
+ dst_size = H5Tget_size(type);
/* Get the names and raw values of all members */
name = calloc(nmembs, sizeof(char *));
@@ -6691,13 +6693,16 @@ xml_print_enum(hid_t type)
char **name = NULL; /*member names */
unsigned char *value = NULL; /*value array */
unsigned nmembs; /*number of members */
+ int snmembs;
hid_t super; /*enum base integer type */
hid_t native = -1; /*native integer datatype */
size_t dst_size; /*destination value type size */
unsigned i; /*miscellaneous counters */
size_t j;
- nmembs = H5Tget_nmembers(type);
+ snmembs = H5Tget_nmembers(type);
+ HDassert(snmembs >= 0);
+ nmembs = (unsigned)snmembs;
super = H5Tget_super(type);
indentation(indent);
diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c
index f5537e1..2e6acc2 100644
--- a/tools/h5stat/h5stat.c
+++ b/tools/h5stat/h5stat.c
@@ -527,10 +527,12 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->dset_comptype[0]++;
for(u = 0; u < (unsigned)nfltr; u++) {
fltr = H5Pget_filter2(dcpl, u, 0, 0, 0, 0, 0, NULL);
- if(fltr < (H5_NFILTERS_IMPL - 1))
- iter->dset_comptype[fltr]++;
- else
- iter->dset_comptype[H5_NFILTERS_IMPL - 1]++; /*other filters*/
+ if(fltr >= 0) {
+ if(fltr < (H5_NFILTERS_IMPL - 1))
+ iter->dset_comptype[fltr]++;
+ else
+ iter->dset_comptype[H5_NFILTERS_IMPL - 1]++; /*other filters*/
+ } /* end if */
} /* end for */
} /* endif nfltr */
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 80016b2..4761ab9 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -2000,10 +2000,10 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
/* calculate the potential number of elements we're going to print */
if(H5Sselect_hyperslab(f_space, H5S_SELECT_SET, temp_start, temp_stride, temp_count, temp_block) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
if((sm_nelmts = H5Sget_select_npoints(f_space)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed");
if (sm_nelmts > 0) {
/*
@@ -2011,7 +2011,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
* a hyperslab whose size is manageable.
*/
if((sm_nbytes = p_type_nbytes = H5Tget_size(p_type)) == 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
if (ctx->ndims > 0)
for (i = ctx->ndims; i > 0; --i) {
@@ -2025,18 +2025,17 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
assert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/
if((sm_buf = HDmalloc((size_t) sm_nelmts * p_type_nbytes)) == NULL)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine");
if((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
if(H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, &zero, NULL, &sm_nelmts, NULL) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
/* read the data */
- if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) {
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed");
- }
+ if(H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0)
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed");
/* print the data */
flags = START_OF_DATA;
@@ -2050,7 +2049,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
/* print array indices. get the lower bound of the hyperslab and calulate
the element position at the start of hyperslab */
if(H5Sget_select_bounds(f_space, low, high) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_select_bounds failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_bounds failed");
elmtno = 0;
for (i = 0; i < (size_t) ctx->ndims - 1; i++) {
@@ -2066,10 +2065,11 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
ctx->sm_pos = elmtno;
h5tools_dump_simple_data(stream, info, dset, ctx, flags, sm_nelmts, p_type, sm_buf);
-done:
+
if(H5Sclose(sm_space) < 0)
- HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
- HDfree(sm_buf);
+ H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+ if(sm_buf)
+ HDfree(sm_buf);
}
else
H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print");
@@ -2272,7 +2272,8 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
hid_t p_type, struct subset_t *sset, int indentlevel)
{
HERR_INIT(herr_t, SUCCEED)
- hid_t f_space; /* file data space */
+ int sndims;
+ hid_t f_space = -1; /* file data space */
size_t i; /* counters */
hsize_t total_size[H5S_MAX_RANK];/* total size of dataset*/
h5tools_context_t ctx; /* print context */
@@ -2288,8 +2289,9 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
memset(&ctx, 0, sizeof(ctx));
ctx.indent_level = indentlevel;
ctx.need_prefix = 1;
- if((ctx.ndims = H5Sget_simple_extent_ndims(f_space)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+ if((sndims = H5Sget_simple_extent_ndims(f_space)) < 0)
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+ ctx.ndims = (unsigned)sndims;
/* assume entire data space to be printed */
if (ctx.ndims > 0)
@@ -2297,10 +2299,11 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
ctx.p_min_idx[i] = 0;
if(H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
ctx.size_last_dim = total_size[ctx.ndims - 1];
h5tools_display_simple_subset(stream, info, &ctx, dset, p_type, sset, f_space, total_size);
+
/* Terminate the output */
if (ctx.cur_column) {
fputs(OPT(info->line_suf, ""), stream);
@@ -2308,11 +2311,10 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
fputs(OPT(info->line_sep, ""), stream);
}
-done:
- if(H5Sclose(f_space) < 0)
- HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
-
CATCH
+ if(f_space >= 0 && H5Sclose(f_space) < 0)
+ H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+
return ret_value;
}
@@ -3291,10 +3293,12 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
H5T_sign_t sign_type; /*sign of value type */
size_t type_size; /*value type size */
size_t dst_size; /*destination value type size */
+ int snmembs;
unsigned i;
- if((nmembs = H5Tget_nmembers(type)) < 0)
+ if((snmembs = H5Tget_nmembers(type)) < 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed");
+ nmembs = (unsigned)snmembs;
assert(nmembs > 0);
if((super = H5Tget_super(type)) < 0)
@@ -3302,6 +3306,7 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
if((type_size = H5Tget_size(type)) <= 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size(type) failed");
+
/*
* Determine what datatype to use for the native values. To simplify
* things we entertain three possibilities:
@@ -3309,21 +3314,18 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
* 2. unsigned long long -- the largest native unsigned integer
* 3. raw format
*/
- if (type_size <= sizeof(long long)) {
+ if(type_size <= sizeof(long long)) {
dst_size = sizeof(long long);
if((sign_type = H5Tget_sign(type))<0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_sign failed");
- if (H5T_SGN_NONE == sign_type) {
+ if(H5T_SGN_NONE == sign_type)
native = H5T_NATIVE_ULLONG;
- }
- else {
+ else
native = H5T_NATIVE_LLONG;
- }
- }
- else {
+ } /* end if */
+ else
dst_size = type_size;
- }
/* Get the names and raw values of all members */
if((name = calloc(nmembs, sizeof(char *))) == NULL)
@@ -3391,7 +3393,7 @@ CATCH
free(value);
if(super >= 0 && H5Tclose(super) < 0)
- H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not close datatype's super class");
if (0 == nmembs)
h5tools_str_append(buffer, "\n<empty>");
diff --git a/tools/lib/h5tools_error.h b/tools/lib/h5tools_error.h
index 9efe223..da8f03c 100644
--- a/tools/lib/h5tools_error.h
+++ b/tools/lib/h5tools_error.h
@@ -116,3 +116,4 @@ extern hid_t H5E_tools_min_id_g;
#define HGOTO_DONE(ret_val) {ret_value = ret_val; goto done;}
#endif /* H5TOOLS_ERROR_H_ */
+