diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2013-09-05 20:44:14 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2013-09-05 20:44:14 (GMT) |
commit | 5b876c929f79003c85585570827452f5d8052d01 (patch) | |
tree | 89a1fa7bb8221a8679f180868467464e331c18ce /tools | |
parent | a1fe10691cf7ce1737aa420191efb996f7fe5657 (diff) | |
download | hdf5-5b876c929f79003c85585570827452f5d8052d01.zip hdf5-5b876c929f79003c85585570827452f5d8052d01.tar.gz hdf5-5b876c929f79003c85585570827452f5d8052d01.tar.bz2 |
[svn-r24101] Description:
Clean up warnings, enable new compiler warning flag(s) and bring back
changes from Coverity branch:
r20813:
Remove the dead code as listed for coverity bug #1722. h5committested.
r20814:
Issue 69: Check return value and throw error if negative return. Also free datatype id on error
r20815:
Use HDstrncpy. --gh
r20816:
Replaced one last HDstrcat call with HDstrncat to resolve coverity issue 832.
r20817:
Use HDstrncpy and HDstrncat. --gh
r20818:
Purpose: Fix valgrind issues with h5jam
Description:
Modified h5jam to free strings strdup'd in parse_command_line before exit. Note
that they may still not be freed in case of error, due to the widespread use of
exit().
r20819:
Issue 80: change loop to use int as loop index.
r20820:
Maintenance: Fixed the bug found by coverity CID 788
There were two problems with this function:
1) it tried to unnecessary free NULL pointer
2) it tried to allocate c_name buffer that is done by H5Pget_class_name
Tested on:
Mac OSX 10.8.4 (amazon) w/gcc 4.8.1, C++ & FORTRAN
(too minor to require h5committest)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump/h5dump_defines.h | 2 | ||||
-rw-r--r-- | tools/h5dump/h5dumpgentest.c | 12 | ||||
-rw-r--r-- | tools/h5jam/h5jam.c | 17 | ||||
-rw-r--r-- | tools/lib/h5diff_array.c | 17 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 28 |
5 files changed, 43 insertions, 33 deletions
diff --git a/tools/h5dump/h5dump_defines.h b/tools/h5dump/h5dump_defines.h index 66d73e3..5f2df43 100644 --- a/tools/h5dump/h5dump_defines.h +++ b/tools/h5dump/h5dump_defines.h @@ -25,7 +25,7 @@ /* Macros for displaying objects */ #define begin_obj(obj,name,begin) \ do { \ - if (name) \ + if ((name)) \ PRINTSTREAM(rawoutstream, "%s \"%s\" %s", (obj), (name), (begin)); \ else \ PRINTSTREAM(rawoutstream, "%s %s", (obj), (begin)); \ diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index 71b1e65..88035a2 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -3839,7 +3839,7 @@ static void write_attr_in(hid_t loc_id, /* create 1D attributes with dimension [2], 2 elements */ hsize_t dims[1]={2}; - char buf1[2][2]= {"ab","de"}; /* string */ + char buf1[2][3]= {"ab","de"}; /* string */ char buf2[2]= {1,2}; /* bitfield, opaque */ s_t buf3[2]= {{1,2},{3,4}}; /* compound */ hobj_ref_t buf4[2]; /* reference */ @@ -3851,7 +3851,7 @@ static void write_attr_in(hid_t loc_id, /* create 2D attributes with dimension [3][2], 6 elements */ hsize_t dims2[2]={3,2}; - char buf12[6][2]= {"ab","cd","ef","gh","ij","kl"}; /* string */ + char buf12[6][3]= {"ab","cd","ef","gh","ij","kl"}; /* string */ char buf22[3][2]= {{1,2},{3,4},{5,6}}; /* bitfield, opaque */ s_t buf32[6]= {{1,2},{3,4},{5,6},{7,8},{9,10},{11,12}}; /* compound */ hobj_ref_t buf42[3][2]; /* reference */ @@ -3862,7 +3862,7 @@ static void write_attr_in(hid_t loc_id, /* create 3D attributes with dimension [4][3][2], 24 elements */ hsize_t dims3[3]={4,3,2}; - char buf13[24][2]= {"ab","cd","ef","gh","ij","kl","mn","pq", + char buf13[24][3]= {"ab","cd","ef","gh","ij","kl","mn","pq", "rs","tu","vw","xz","AB","CD","EF","GH", "IJ","KL","MN","PQ","RS","TU","VW","XZ"}; /* string */ char buf23[4][3][2]; /* bitfield, opaque */ @@ -4281,7 +4281,7 @@ static void write_dset_in(hid_t loc_id, /* create 1D attributes with dimension [2], 2 elements */ hsize_t dims[1]={2}; - char buf1[2][2]= {"ab","de"}; /* string */ + char buf1[2][3]= {"ab","de"}; /* string */ char buf2[2]= {1,2}; /* bitfield, opaque */ s_t buf3[2]= {{1,2},{3,4}}; /* compound */ hobj_ref_t buf4[2]; /* reference */ @@ -4293,7 +4293,7 @@ static void write_dset_in(hid_t loc_id, /* create 2D attributes with dimension [3][2], 6 elements */ hsize_t dims2[2]={3,2}; - char buf12[6][2]= {"ab","cd","ef","gh","ij","kl"}; /* string */ + char buf12[6][3]= {"ab","cd","ef","gh","ij","kl"}; /* string */ char buf22[3][2]= {{1,2},{3,4},{5,6}}; /* bitfield, opaque */ s_t buf32[6]= {{1,2},{3,4},{5,6},{7,8},{9,10},{11,12}}; /* compound */ hobj_ref_t buf42[3][2]; /* reference */ @@ -4304,7 +4304,7 @@ static void write_dset_in(hid_t loc_id, /* create 3D attributes with dimension [4][3][2], 24 elements */ hsize_t dims3[3]={4,3,2}; - char buf13[24][2]= {"ab","cd","ef","gh","ij","kl","mn","pq", + char buf13[24][3]= {"ab","cd","ef","gh","ij","kl","mn","pq", "rs","tu","vw","xz","AB","CD","EF","GH", "IJ","KL","MN","PQ","RS","TU","VW","XZ"}; /* string */ char buf23[4][3][2]; /* bitfield, opaque */ diff --git a/tools/h5jam/h5jam.c b/tools/h5jam/h5jam.c index 52eb0aa..ab38f65 100644 --- a/tools/h5jam/h5jam.c +++ b/tools/h5jam/h5jam.c @@ -327,7 +327,7 @@ main (int argc, const char *argv[]) leave (EXIT_FAILURE); } - h5fsize = sbuf2.st_size; + h5fsize = (hsize_t)sbuf2.st_size; if (output_file == NULL) { ofid = HDopen (input_file, O_WRONLY, 0); @@ -385,16 +385,19 @@ main (int argc, const char *argv[]) /* pad the ub */ where = write_pad (ofid, where); - if (ub_file) + if(ub_file) HDfree (ub_file); - if (input_file) + if(input_file) HDfree (input_file); - if (output_file) + if(output_file) HDfree (output_file); - if (ufid >= 0) HDclose (ufid); - if (h5fid >= 0) HDclose (h5fid); - if (ofid >= 0) HDclose (ofid); + if(ufid >= 0) + HDclose (ufid); + if(h5fid >= 0) + HDclose (h5fid); + if(ofid >= 0) + HDclose (ofid); return h5tools_getstatus(); } diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 96b508d..7dba0e5 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -109,7 +109,7 @@ static hbool_t not_comparable; if(0 == (A) && 0 == (B)) \ both_zero = TRUE; \ if(0 != (A)) \ - per = (double)ABS((double)(B - A) / (double)A); \ + per = (double)ABS((double)((B) - (A)) / (double)(A)); \ else \ not_comparable = TRUE; \ } @@ -119,16 +119,16 @@ static hbool_t not_comparable; per = -1; \ not_comparable = FALSE; \ both_zero = FALSE; \ - if(A == 0 && B == 0) \ + if((A) == 0 && (B) == 0) \ both_zero = TRUE; \ - if(A != 0) \ - per = ABS((double)((TYPE)(B - A)) / (double)A) ; \ + if((A) != 0) \ + per = ABS((double)((TYPE)((B) - (A))) / (double)(A)) ; \ else \ not_comparable = TRUE; \ } -# define PDIFF(a,b) ( (b>a) ? (b-a) : (a-b)) +#define PDIFF(a,b) (((b) > (a)) ? ((b) - (a)) : ((a) -(b))) typedef struct mcomp_t { @@ -890,9 +890,8 @@ static hsize_t diff_datum(void *_mem1, /* calculate the number of array elements */ for (u = 0, nelmts = 1; u < (unsigned)ndims; u++) nelmts *= adims[u]; - for (u = 0; u < nelmts; u++) - { - nfound+=diff_datum( + for (u = 0; u < nelmts; u++) { + nfound += diff_datum( mem1 + u * size, mem2 + u * size, /* offset */ memb_type, @@ -907,7 +906,7 @@ static hsize_t diff_datum(void *_mem1, container1_id, container2_id, ph, members); - } + } H5Tclose(memb_type); } break; diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 7b43d2e..d9a1827 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -1443,8 +1443,10 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t offset = H5Tget_member_offset(tid, j); memb = H5Tget_member_type(tid, j); - if (render_bin_output(stream, container, memb, mem + offset, 1) < 0) - return FAIL; + if (render_bin_output(stream, container, memb, mem + offset, 1) < 0) { + H5Tclose(memb); + H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output of compound member failed"); + } H5Tclose(memb); } @@ -1473,8 +1475,10 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char*)_mem) + block_index * size; /* dump the array element */ - if (render_bin_output(stream, container, memb, mem, nelmts) < 0) + if (render_bin_output(stream, container, memb, mem, nelmts) < 0) { + H5Tclose(memb); H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); + } } H5Tclose(memb); } @@ -1493,8 +1497,10 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t nelmts = ((hvl_t *) mem)->len; /* dump the array element */ - if (render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)), nelmts) < 0) + if (render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)), nelmts) < 0) { + H5Tclose(memb); H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); + } } H5Tclose(memb); } @@ -1615,15 +1621,16 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, } if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dread failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - render_bin_output(stream, container, type_id, (char*)region_buf, numelem); + if(render_bin_output(stream, container, type_id, (char*)region_buf, numelem) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "render_bin_output of data region failed"); /* Render the region data element end */ } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ @@ -1753,9 +1760,10 @@ render_bin_output_region_data_points(hid_t region_space, hid_t region_id, if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); if(H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - render_bin_output(stream, container, type_id, (char*)region_buf, npoints); + if(render_bin_output(stream, container, type_id, (char*)region_buf, npoints) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "render_bin_output of data points failed"); done: HDfree(region_buf); |