summaryrefslogtreecommitdiffstats
path: root/tools
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 /tools
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 'tools')
-rw-r--r--tools/h5jam/h5unjam.c165
-rw-r--r--tools/lib/h5tools.c52
2 files changed, 99 insertions, 118 deletions
diff --git a/tools/h5jam/h5unjam.c b/tools/h5jam/h5unjam.c
index c304045..18b5f11 100644
--- a/tools/h5jam/h5unjam.c
+++ b/tools/h5jam/h5unjam.c
@@ -43,14 +43,14 @@ static const char *s_opts = "hu:i:o:d:V";
static struct long_options l_opts[] = {
{ "help", no_arg, 'h' },
{ "hel", no_arg, 'h' },
- {"i", require_arg, 'i'}, /* input file */
- {"u", require_arg, 'u'}, /* user block file */
- {"o", require_arg, 'o'}, /* output file */
- {"delete", no_arg, 'd'}, /* delete ub */
- {"delet", no_arg, 'd'},
- {"dele", no_arg, 'd'},
- {"del", no_arg, 'd'},
- {"de", no_arg, 'd'},
+ {"i", require_arg, 'i'}, /* input file */
+ {"u", require_arg, 'u'}, /* user block file */
+ {"o", require_arg, 'o'}, /* output file */
+ {"delete", no_arg, 'd'}, /* delete ub */
+ {"delet", no_arg, 'd'},
+ {"dele", no_arg, 'd'},
+ {"del", no_arg, 'd'},
+ {"de", no_arg, 'd'},
{ NULL, 0, '\0' }
};
@@ -123,86 +123,69 @@ usage(const char *prog)
}
/*-------------------------------------------------------------------------
- * Function: leave
- *
- * Purpose: Shutdown and call exit()
- *
- * Return: Does not return
- *
- *-------------------------------------------------------------------------
- */
-static void
-leave(int ret)
-{
- if (ub_file)
- HDfree (ub_file);
- if (input_file)
- HDfree (input_file);
- if (output_file)
- HDfree (output_file);
-
- h5tools_close();
-
- HDexit(ret);
-}
-
-/*-------------------------------------------------------------------------
* Function: parse_command_line
*
* Purpose: Parse the command line for the h5dumper.
*
- * Return: Success:
+ * Return: Success: EXIT_SUCCESS;
*
- * Failure: Exits program with EXIT_FAILURE value.
- *
- * Programmer:
- *
- * Modifications:
+ * Failure: Exits function with EXIT_FAILURE value.
*
*-------------------------------------------------------------------------
*/
-
-static void
+static int
parse_command_line(int argc, const char *argv[])
{
int opt = FALSE;
/* parse command line options */
while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
- switch ((char) opt) {
- case 'o':
- output_file = HDstrdup (opt_arg);
- break;
- case 'i':
- input_file = HDstrdup (opt_arg);
- break;
- case 'u':
- ub_file = HDstrdup (opt_arg);
- break;
- case 'd':
- do_delete = TRUE;
- break;
- case 'h':
- usage(h5tools_getprogname());
- leave(EXIT_SUCCESS);
- case 'V':
- print_version(h5tools_getprogname());
- leave(EXIT_SUCCESS);
- case '?':
- default:
- usage(h5tools_getprogname());
- leave(EXIT_FAILURE);
+ switch((char)opt) {
+ case 'o':
+ output_file = HDstrdup(opt_arg);
+ break;
+
+ case 'i':
+ input_file = HDstrdup(opt_arg);
+ break;
+
+ case 'u':
+ ub_file = HDstrdup(opt_arg);
+ break;
+
+ case 'd':
+ do_delete = TRUE;
+ break;
+
+ case 'h':
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_SUCCESS);
+ goto done;
+
+ case 'V':
+ print_version (h5tools_getprogname());
+ h5tools_setstatus(EXIT_SUCCESS);
+ goto done;
+
+ case '?':
+ default:
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
}
}
- /* check for file name to be processed */
-/*
- if (argc <= opt_ind+2) {
- error_msg("missing file name\n");
- usage(h5tools_getprogname());
- HDexit(EXIT_FAILURE);
- }
-*/
+ return EXIT_SUCCESS;
+
+done:
+ if(input_file)
+ HDfree(input_file);
+ if(output_file)
+ HDfree(output_file);
+ if(ub_file)
+ HDfree(ub_file);
+
+ return EXIT_FAILURE;
}
/*-------------------------------------------------------------------------
@@ -246,13 +229,15 @@ main(int argc, const char *argv[])
/* Initialize h5tools lib */
h5tools_init();
- parse_command_line(argc, argv);
+ if(EXIT_FAILURE == parse_command_line(argc, argv))
+ goto done;
if (input_file == NULL) {
/* no user block */
error_msg("missing arguemnt for HDF5 file input.\n");
help_ref_msg(stderr);
- leave (EXIT_FAILURE);
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
}
testval = H5Fis_hdf5(input_file);
@@ -286,8 +271,10 @@ main(int argc, const char *argv[])
goto done;
}
- H5Pclose(plist);
- H5Fclose(ifile);
+ status = H5Pclose(plist);
+ HDassert(status >= 0);
+ status = H5Fclose(ifile);
+ HDassert(status >= 0);
if (usize == 0) {
/* no user block to remove: message? */
@@ -320,7 +307,7 @@ main(int argc, const char *argv[])
if (ub_file == NULL) {
/* write to sdtout */
- ufid = HDdup(1);
+ ufid = STDOUT_FILENO;
}
else {
ufid = HDopen(ub_file,O_WRONLY|O_CREAT|O_TRUNC, 0644 );
@@ -371,17 +358,25 @@ main(int argc, const char *argv[])
}
done:
- if (ub_file) {
- HDfree (ub_file);
- if (ufid >= 0) HDclose(ufid);
+ if(input_file)
+ HDfree(input_file);
+ if(output_file)
+ HDfree(output_file);
+ if(ub_file) {
+ HDfree(ub_file);
+ if(ufid >= 0)
+ status = HDclose(ufid);
+ HDassert(status >= 0);
}
- if (input_file)
- HDfree (input_file);
- if (output_file)
- HDfree (output_file);
- if (h5fid >= 0) HDclose(h5fid);
- if (ifid >= 0) HDclose(ifid);
+ if(h5fid >= 0) {
+ status = HDclose(h5fid);
+ HDassert(status >= 0);
+ }
+ if(ifid >= 0) {
+ status = HDclose(ifid);
+ HDassert(status >= 0);
+ }
return h5tools_getstatus();
}
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 66c0e64..0d9bc15 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -30,10 +30,6 @@
#include "h5tools_utils.h"
#include "H5private.h"
-#define SANITY_CHECK
-
-#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z))
-
/* global variables */
hid_t H5tools_ERR_STACK_g = 0;
hid_t H5tools_ERR_CLS_g = -1;
@@ -1122,7 +1118,6 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
while(block_index > 0) {
size_t bytes_in = 0; /* # of bytes to write */
size_t bytes_wrote = 0; /* # of bytes written */
- size_t item_size = size; /* size of items in bytes */
if(block_index > sizeof(size_t))
bytes_in = sizeof(size_t);
@@ -1168,16 +1163,21 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
break;
case H5T_COMPOUND:
{
- unsigned j;
- hid_t memb;
+ int snmembs;
unsigned nmembs;
- size_t offset;
- nmembs = H5Tget_nmembers(tid);
+ if((snmembs = H5Tget_nmembers(tid)) < 0)
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers of compound failed");
+ nmembs = (unsigned)snmembs;
for (block_index = 0; block_index < block_nelmts; block_index++) {
+ unsigned j;
+
mem = ((unsigned char*)_mem) + block_index * size;
for (j = 0; j < nmembs; j++) {
+ hid_t memb;
+ size_t offset;
+
offset = H5Tget_member_offset(tid, j);
memb = H5Tget_member_type(tid, j);
@@ -1192,7 +1192,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
case H5T_ARRAY:
{
int k, ndims;
- hsize_t i, dims[H5S_MAX_RANK], temp_nelmts, nelmts;
+ hsize_t dims[H5S_MAX_RANK], temp_nelmts, nelmts;
hid_t memb;
/* get the array's base datatype for each element */
@@ -1219,7 +1219,6 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
break;
case H5T_VLEN:
{
- unsigned int i;
hsize_t nelmts;
hid_t memb;
@@ -1305,10 +1304,9 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream,
hsize_t *start = NULL;
hsize_t *count = NULL;
hsize_t numelem;
- hsize_t numindex;
hsize_t total_size[H5S_MAX_RANK];
int jndx;
- int type_size;
+ size_t type_size;
hid_t mem_space = -1;
void *region_buf = NULL;
int blkndx;
@@ -1399,15 +1397,17 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
FILE *stream, hid_t container)
{
HERR_INIT(hbool_t, TRUE)
- hssize_t nblocks;
+ hssize_t snblocks;
+ hsize_t nblocks;
hsize_t alloc_size;
- hsize_t *ptdata = NULL;
+ hsize_t *ptdata;
int ndims;
hid_t dtype;
hid_t type_id;
- if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
+ if((snblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed");
+ nblocks = (hsize_t)snblocks;
/* Print block information */
if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
@@ -1463,13 +1463,12 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
* hssize_t npoints is the number of points in the region
*-------------------------------------------------------------------------
*/
-int
+static int
render_bin_output_region_data_points(hid_t region_space, hid_t region_id,
FILE *stream, hid_t container,
- int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata)
+ int ndims, hid_t type_id, hssize_t npoints)
{
hsize_t *dims1 = NULL;
- int jndx;
int type_size;
hid_t mem_space = -1;
void *region_buf = NULL;
@@ -1525,8 +1524,6 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id,
{
HERR_INIT(hbool_t, TRUE)
hssize_t npoints;
- hsize_t alloc_size;
- hsize_t *ptdata;
int ndims;
hid_t dtype;
hid_t type_id;
@@ -1538,15 +1535,6 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id,
if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
- alloc_size = npoints * ndims * sizeof(ptdata[0]);
- HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/
- if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size)))
- HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata");
-
- H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t);
- if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0)
- HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed");
-
if((dtype = H5Dget_type(region_id)) < 0)
HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Dget_type failed");
@@ -1554,11 +1542,9 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id,
HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Tget_native_type failed");
render_bin_output_region_data_points(region_space, region_id,
- stream, container, ndims, type_id, npoints, ptdata);
+ stream, container, ndims, type_id, npoints);
done:
- HDfree(ptdata);
-
if(H5Tclose(type_id) < 0)
HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed");