From 8e2cedd066e4569bf36b530495bd2f811d95f808 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 23 Oct 2017 09:26:15 -0500 Subject: HDFFV-10297 Cleanup, Initialize variables --- tools/lib/h5diff_dset.c | 2 +- tools/lib/h5tools.c | 464 +++++++++++++++---------------------- tools/lib/h5tools_dump.c | 11 +- tools/lib/h5tools_str.c | 8 +- tools/lib/h5tools_utils.c | 5 +- tools/src/h5repack/h5repack.c | 8 +- tools/src/h5repack/h5repack_copy.c | 28 +-- tools/src/h5repack/h5repack_refs.c | 15 +- 8 files changed, 224 insertions(+), 317 deletions(-) diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index b03295b..ee42b99 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -189,7 +189,7 @@ hsize_t diff_datasetid(hid_t did1, void *buf2 = NULL; void *sm_buf1 = NULL; void *sm_buf2 = NULL; - hid_t sm_space; /*stripmine data space */ + hid_t sm_space = -1; /*stripmine data space */ size_t need; /* bytes needed for malloc */ int i; unsigned int vl_data = 0; /*contains VL datatypes */ diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 344913a..6ea5e47 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -23,10 +23,10 @@ #include "H5private.h" /* global variables */ -hid_t H5tools_ERR_STACK_g = 0; -hid_t H5tools_ERR_CLS_g = -1; -hid_t H5E_tools_g = -1; -hid_t H5E_tools_min_id_g = -1; +hid_t H5tools_ERR_STACK_g = 0; +hid_t H5tools_ERR_CLS_g = -1; +hid_t H5E_tools_g = -1; +hid_t H5E_tools_min_id_g = -1; int compound_data; FILE *rawattrstream = NULL; /* should initialize to stdout but gcc moans about it */ FILE *rawdatastream = NULL; /* should initialize to stdout but gcc moans about it */ @@ -77,18 +77,13 @@ typedef enum { #define NUM_DRIVERS (sizeof(drivernames) / sizeof(drivernames[0])) /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Initialize the H5 Tools library - * Description: - * This should be called before any other h5tools function is called. - * Effect of any h5tools function called before this has been called is - * undetermined. - * Return: - * None - * Programmer: - * Albert Cheng, 2000-10-31 - * Modifications: + * Function: h5tools_init + * + * Purpose: This should be called before any other h5tools function is called. + * Effect of any h5tools function called before this has been called is + * undetermined. + * + * Return None *------------------------------------------------------------------------- */ void @@ -121,19 +116,14 @@ h5tools_init(void) } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Close the H5 Tools library - * Description: - * Close or release resources such as files opened by the library. This - * should be called after all other h5tools functions have been called. - * Effect of any h5tools function called after this has been called is - * undetermined. - * Return: - * None - * Programmer: - * Albert Cheng, 2000-10-31 - * Modifications: + * Function: h5tools_close + * + * Purpose: Close or release resources such as files opened by the library. This + * should be called after all other h5tools functions have been called. + * Effect of any h5tools function called after this has been called is + * undetermined. + * + * Return: None *------------------------------------------------------------------------- */ void @@ -193,19 +183,13 @@ h5tools_close(void) } /*------------------------------------------------------------------------- - * Function: h5tools_set_data_output_file - * - * Purpose: Open fname as the output file for dataset raw data. - * Set rawdatastream as its file stream. + * Function: h5tools_set_data_output_file * - * Return: 0 -- succeeded - * negative -- failed - * - * Programmer: Albert Cheng, 2000/09/30 - * - * Modifications: - * pvn June, 1, 2006. Add a switch for binary output + * Purpose: Open fname as the output file for dataset raw data. + * Set rawdatastream as its file stream. * + * Return: 0 -- succeeded + * negative -- failed *------------------------------------------------------------------------- */ int @@ -247,14 +231,13 @@ h5tools_set_data_output_file(const char *fname, int is_bin) } /*------------------------------------------------------------------------- - * Function: h5tools_set_attr_output_file + * Function: h5tools_set_attr_output_file * - * Purpose: Open fname as the output file for attribute raw data. - * Set rawattrstream as its file stream. - * - * Return: 0 -- succeeded - * negative -- failed + * Purpose: Open fname as the output file for attribute raw data. + * Set rawattrstream as its file stream. * + * Return: 0 -- succeeded + * negative -- failed *------------------------------------------------------------------------- */ int @@ -296,13 +279,13 @@ h5tools_set_attr_output_file(const char *fname, int is_bin) } /*------------------------------------------------------------------------- - * Function: h5tools_set_input_file + * Function: h5tools_set_input_file * - * Purpose: Open fname as the input file for raw input. - * Set rawinstream as its file stream. + * Purpose: Open fname as the input file for raw input. + * Set rawinstream as its file stream. * - * Return: 0 -- succeeded - * negative -- failed + * Return: 0 -- succeeded + * negative -- failed * *------------------------------------------------------------------------- */ @@ -344,13 +327,13 @@ h5tools_set_input_file(const char *fname, int is_bin) } /*------------------------------------------------------------------------- - * Function: h5tools_set_output_file + * Function: h5tools_set_output_file * - * Purpose: Open fname as the output file for raw output. - * Set rawoutstream as its file stream. + * Purpose: Open fname as the output file for raw output. + * Set rawoutstream as its file stream. * - * Return: 0 -- succeeded - * negative -- failed + * Return: 0 -- succeeded + * negative -- failed * *------------------------------------------------------------------------- */ @@ -392,14 +375,13 @@ h5tools_set_output_file(const char *fname, int is_bin) } /*------------------------------------------------------------------------- - * Function: h5tools_set_error_file - * - * Purpose: Open fname as the error output file for dataset raw error. - * Set rawerrorstream as its file stream. + * Function: h5tools_set_error_file * - * Return: 0 -- succeeded - * negative -- failed + * Purpose: Open fname as the error output file for dataset raw error. + * Set rawerrorstream as its file stream. * + * Return: 0 -- succeeded + * negative -- failed *------------------------------------------------------------------------- */ int @@ -441,33 +423,28 @@ h5tools_set_error_file(const char *fname, int is_bin) } /*------------------------------------------------------------------------- - * Audience: Private - * Chapter: H5Tools Library - * Purpose: Get a FAPL for a driver - * Description: - * Get a FAPL for a given VFL driver name. - * Return: - * None - * Programmer: - * Quincey Koziol, 2004-02-04 - * Modifications: - * Pedro Vicente Nunes, Thursday, July 27, 2006 - * Added error return conditions for the H5Pset_fapl calls + * Function: h5tools_get_fapl + * + * Purpose: Get a FAPL for a given VFL driver name. + * + * Return: positive - succeeded + * negative - failed *------------------------------------------------------------------------- */ static hid_t h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) { - hid_t new_fapl; /* Copy of file access property list passed in, or new property list */ + hid_t new_fapl = -1; /* Copy of file access property list passed in, or new property list */ + int ret_value = SUCCEED; /* Make a copy of the FAPL, for the file open call to use, eventually */ if (fapl == H5P_DEFAULT) { if ((new_fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcreate failed"); } /* end if */ else { if ((new_fapl = H5Pcopy(fapl)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcopy failed"); } /* end else */ /* Determine which driver the user wants to open the file with. Try @@ -475,7 +452,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) if (!HDstrcmp(driver, drivernames[SEC2_IDX])) { /* SEC2 driver */ if (H5Pset_fapl_sec2(new_fapl) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_fapl_sec2 failed"); if (drivernum) *drivernum = SEC2_IDX; @@ -487,7 +464,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) * is the member size. */ if (H5Pset_fapl_family(new_fapl, (hsize_t) 0, H5P_DEFAULT) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_fapl_family failed"); if (drivernum) *drivernum = FAMILY_IDX; @@ -495,7 +472,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) else if (!HDstrcmp(driver, drivernames[SPLIT_IDX])) { /* SPLIT Driver */ if (H5Pset_fapl_split(new_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_fapl_split failed"); if (drivernum) *drivernum = SPLIT_IDX; @@ -503,7 +480,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) else if (!HDstrcmp(driver, drivernames[MULTI_IDX])) { /* MULTI Driver */ if (H5Pset_fapl_multi(new_fapl, NULL, NULL, NULL, NULL, TRUE) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_fapl_multi failed"); if(drivernum) *drivernum = MULTI_IDX; @@ -519,29 +496,28 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) if(mpi_initialized && !mpi_finalized) { if(H5Pset_fapl_mpio(new_fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_fapl_mpio failed"); if(drivernum) *drivernum = MPIO_IDX; } /* end if */ } #endif /* H5_HAVE_PARALLEL */ else - goto error; + ret_value = -1; - return(new_fapl); - -error: - if(new_fapl != H5P_DEFAULT) +done: + if((new_fapl != H5P_DEFAULT) && (ret_value < 0)) { H5Pclose(new_fapl); - return -1; + new_fapl = -1; + } + + return(new_fapl); } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Open a file with various VFL drivers. - * Description: - * Loop through the various types of VFL drivers trying to open FNAME. + * Function: h5tools_fopen + * + * Purpose: Loop through the various types of VFL drivers trying to open FNAME. * If the HDF5 library is version 1.2 or less, then we have only the SEC2 * driver to try out. If the HDF5 library is greater than version 1.2, * then we have the FAMILY, SPLIT, and MULTI drivers to play with. @@ -549,6 +525,7 @@ error: * If DRIVER is non-NULL, then it will try to open the file with that * driver first. We assume that the user knows what they are doing so, if * we fail, then we won't try other file drivers. + * * Return: * On success, returns a file id for the opened file. If DRIVERNAME is * non-null then the first DRIVERNAME_SIZE-1 characters of the driver @@ -556,38 +533,6 @@ error: * * Otherwise, the function returns FAIL. If DRIVERNAME is non-null then * the first byte is set to the null terminator. - * Programmer: - * Lost in the mists of time. - * Modifications: - * Robb Matzke, 2000-06-23 - * We only have to initialize driver[] on the first call, thereby - * preventing memory leaks from repeated calls to H5Pcreate(). - * - * Robb Matzke, 2000-06-23 - * Added DRIVERNAME_SIZE arg to prevent overflows when writing to - * DRIVERNAME. - * - * Robb Matzke, 2000-06-23 - * Added test to prevent coredump when the file could not be opened by - * any driver. - * - * Robb Matzke, 2000-06-23 - * Changed name from H5ToolsFopen() so it jives better with the names we - * already have at the top of this source file. - * - * Thomas Radke, 2000-09-12 - * Added Stream VFD to the driver[] array. - * - * Bill Wendling, 2001-01-10 - * Changed macro behavior so that if we have a version other than 1.2.x - * (i.e., > 1.2), then we do the drivers check. - * - * Bill Wendling, 2001-07-30 - * Added DRIVER parameter so that the user can specify "try this driver" - * instead of the default behaviour. If it fails to open the file with - * that driver, this will fail completely (i.e., we won't try the other - * drivers). We're assuming the user knows what they're doing. How UNIX - * of us. *------------------------------------------------------------------------- */ hid_t @@ -652,18 +597,13 @@ done: } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Count the number of columns in a string. - * Description: - * Count the number of columns in a string. This is the number of - * characters in the string not counting line-control characters. - * Return: - * On success, returns the width of the string. Otherwise this function - * returns 0. - * Programmer: - * Robb Matzke, Tuesday, April 27, 1999 - * Modifications: + * Function: h5tools_count_ncols + * + * Purpose: Count the number of columns in a string. This is the number of + * characters in the string not counting line-control characters. + * + * Return: success - returns the width of the string. + * failure - 0. *------------------------------------------------------------------------- */ H5_ATTR_PURE static size_t @@ -681,20 +621,17 @@ h5tools_count_ncols(const char *s) /*------------------------------------------------------------------------- * Function: h5tools_detect_vlen * - * Purpose: Recursive check for any variable length data in given type. + * Purpose: Recursive check for any variable length data in given type. * - * Return: - * TRUE : type conatains any variable length data - * FALSE : type doesn't contain any variable length data - * Negative value: error occur - * - * Programmer: Jonathan Kim March 18, 2011 + * Return: TRUE : type conatains any variable length data + * FALSE : type doesn't contain any variable length data + * Negative value: error occur *------------------------------------------------------------------------- */ htri_t h5tools_detect_vlen(hid_t tid) { - htri_t ret; + htri_t ret = FALSE; /* recursive detect any vlen data values in type (compound, array ...) */ ret = H5Tdetect_class(tid, H5T_VLEN); @@ -713,20 +650,18 @@ done: /*------------------------------------------------------------------------- * Function: h5tools_detect_vlen_str * - * Purpose: Recursive check for variable length string of a datatype. - * - * Return: - * TRUE : type conatains any variable length string - * FALSE : type doesn't contain any variable length string - * Negative value: error occur + * Purpose: Recursive check for variable length string of a datatype. * + * Return: TRUE : type conatains any variable length string + * FALSE : type doesn't contain any variable length string + * Negative value: error occur *------------------------------------------------------------------------- */ htri_t h5tools_detect_vlen_str(hid_t tid) { H5T_class_t tclass = -1; - htri_t ret = FALSE; + htri_t ret = FALSE; ret = H5Tis_variable_str(tid); if((ret == TRUE) || (ret < 0)) @@ -774,25 +709,13 @@ done: } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Emit a simple prefix to STREAM. - * Description: - * If /ctx->need_prefix/ is set then terminate the current line (if - * applicable), calculate the prefix string, and display it at the start - * of a line. - * Return: - * None - * Programmer: - * Robb Matzke, Monday, April 26, 1999 - * Modifications: - * Robb Matzke, 1999-09-29 - * If a new prefix is printed then the current element number is set back - * to zero. - * pvn, 2004-07-08 - * Added support for printing array indices: - * the indentation is printed before the prefix (printed one indentation - * level before) + * Function: h5tools_simple_prefix + * + * Purpose: If /ctx->need_prefix/ is set then terminate the current line (if + * applicable), calculate the prefix string, and display it at the start + * of a line. + * + * Return: None *------------------------------------------------------------------------- */ void @@ -800,7 +723,7 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hsize_t elmtno, int secnum) { h5tools_str_t prefix; - h5tools_str_t str; /*temporary for indentation */ + h5tools_str_t str; /*temporary for indentation */ size_t templength = 0; unsigned u, indentlevel = 0; @@ -871,15 +794,13 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Emit a simple prefix to STREAM. - * Description: - * If /ctx->need_prefix/ is set then terminate the current line (if - * applicable), calculate the prefix string, and display it at the start - * of a line. Calls region specific function. - * Return: - * None + * Function: h5tools_region_simple_prefix + * + * Purpose: If /ctx->need_prefix/ is set then terminate the current line (if + * applicable), calculate the prefix string, and display it at the start + * of a line. Calls region specific function. + * + * Return: None *------------------------------------------------------------------------- */ void @@ -887,7 +808,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum) { h5tools_str_t prefix; - h5tools_str_t str; /*temporary for indentation */ + h5tools_str_t str; /*temporary for indentation */ size_t templength = 0; unsigned u, indentlevel = 0; @@ -958,28 +879,26 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Render an element to output STREAM. - * Description: - * Prints the string buffer to the output STREAM. The string is - * printed according to the format described in INFO. The CTX struct - * contains context information shared between calls to this function. + * Function: h5tools_render_element * - * Return: - * False if a dimension end is reached, otherwise true + * Purpose: Prints the string buffer to the output STREAM. The string is + * printed according to the format described in INFO. The CTX struct + * contains context information shared between calls to this function. + * + * Return: False if a dimension end is reached + * True otherwise * * In/Out: - * h5tools_context_t *ctx - * h5tools_str_t *buffer - * hsize_t *curr_pos + * h5tools_context_t *ctx + * h5tools_str_t *buffer + * hsize_t *curr_pos * * Parameters Description: - * h5tools_str_t *buffer is the string into which to render - * hsize_t curr_pos is the total data element position - * size_t ncols - * hsize_t local_elmt_counter is the local element loop counter - * hsize_t elmt_count is the data element loop counter + * h5tools_str_t *buffer is the string into which to render + * hsize_t curr_pos is the total data element position + * size_t ncols + * hsize_t local_elmt_counter is the local element loop counter + * hsize_t elmt_count is the data element loop counter *------------------------------------------------------------------------- */ hbool_t @@ -988,10 +907,10 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, size_t ncols, hsize_t local_elmt_counter, hsize_t elmt_counter) { hbool_t dimension_break = TRUE; - char *s; - char *section; /*a section of output */ - int secnum; /*section sequence number */ - int multiline; /*datum was multiline */ + char *s = NULL; + char *section = NULL; /* a section of output */ + int secnum; /* section sequence number */ + int multiline; /* datum was multiline */ if (stream == NULL) return dimension_break; @@ -1114,29 +1033,28 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Render a region element to output STREAM. - * Description: - * Prints the string buffer to the output STREAM. The string is - * printed according to the format described in INFO. The CTX struct - * contains context information shared between calls to this function. + * Function: h5tools_render_region_element + * + * Purpose: Prints the string buffer to the output STREAM. The string is + * printed according to the format described in INFO. The CTX struct + * contains context information shared between calls to this function. * * Return: - * False if a dimension end is reached, otherwise true + * False if a dimension end is reached + * True otherwise * * In/Out: - * h5tools_context_t *ctx - * h5tools_str_t *buffer - * hsize_t *curr_pos + * h5tools_context_t *ctx + * h5tools_str_t *buffer + * hsize_t *curr_pos * * Parameters Description: - * h5tools_str_t *buffer is the string into which to render - * hsize_t curr_pos is the total data element position - * size_t ncols - * hsize_t *ptdata - * hsize_t local_elmt_counter is the local element loop counter - * hsize_t elmt_count is the data element loop counter + * h5tools_str_t *buffer is the string into which to render + * hsize_t curr_pos is the total data element position + * size_t ncols + * hsize_t *ptdata + * hsize_t local_elmt_counter is the local element loop counter + * hsize_t elmt_count is the data element loop counter *------------------------------------------------------------------------- */ hbool_t @@ -1145,10 +1063,10 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, size_t ncols, hsize_t *ptdata, hsize_t local_elmt_counter, hsize_t elmt_counter) { hbool_t dimension_break = TRUE; - char *s; - char *section; /*a section of output */ - int secnum; /*section sequence number */ - int multiline; /*datum was multiline */ + char *s = NULL; + char *section = NULL; /* a section of output */ + int secnum; /* section sequence number */ + int multiline; /* datum was multiline */ s = h5tools_str_fmt(buffer, (size_t)0, "%s"); @@ -1270,11 +1188,11 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Function: init_acc_pos + * Function: init_acc_pos * - * Purpose: initialize accumulator and matrix position + * Purpose: initialize accumulator and matrix position * - * Return: void + * Return: void *------------------------------------------------------------------------- */ void @@ -1295,10 +1213,10 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) /*------------------------------------------------------------------------- * Function: render_bin_output * - * Purpose: Write one element of memory buffer to a binary file stream + * Purpose: Write one element of memory buffer to a binary file stream * - * Return: Success: SUCCEED - * Failure: FAIL + * Return: Success: SUCCEED + * Failure: FAIL *------------------------------------------------------------------------- */ int @@ -1344,7 +1262,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t { unsigned int i; H5T_str_t pad; - char *s; + char *s = NULL; unsigned char tempuchar; pad = H5Tget_strpad(tid); @@ -1372,7 +1290,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t break; case H5T_COMPOUND: { - int snmembs; + int snmembs; unsigned nmembs; if((snmembs = H5Tget_nmembers(tid)) < 0) @@ -1384,7 +1302,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t mem = ((unsigned char*)_mem) + block_index * size; for (j = 0; j < nmembs; j++) { - hid_t memb; + hid_t memb = -1; size_t offset; offset = H5Tget_member_offset(tid, j); @@ -1404,7 +1322,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t { int k, ndims; hsize_t dims[H5S_MAX_RANK], temp_nelmts, nelmts; - hid_t memb; + hid_t memb = -1; /* get the array's base datatype for each element */ memb = H5Tget_super(tid); @@ -1437,7 +1355,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t case H5T_VLEN: { hsize_t nelmts; - hid_t memb; + hid_t memb = -1; /* get the VL sequences's base datatype for each element */ memb = H5Tget_super(tid); @@ -1462,7 +1380,8 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t /* if (H5Tequal(tid, H5T_STD_REF_DSETREG)) */ if (region_output) { /* region data */ - hid_t region_id, region_space; + hid_t region_id = -1; + hid_t region_space = -1; H5S_sel_type region_type; for (block_index = 0; block_index < block_nelmts; block_index++) { @@ -1512,15 +1431,13 @@ CATCH } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print the data values from a dataset referenced by region blocks. + * Function: render_bin_output_region_data_blocks * - * Description: - * This is a special case subfunction to print the data in a region reference of type blocks. + * Purpose: Print the data values from a dataset referenced by region blocks. + * This is a special case subfunction to print the data in a region reference of type blocks. * - * Return: - * The function returns FAIL if there was an error, otherwise SUCEED + * Return: FAIL if there was an error + * SUCCEED otherwise * *------------------------------------------------------------------------- */ @@ -1609,16 +1526,13 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print some values from a dataset referenced by region blocks. - * - * Description: - * This is a special case subfunction to dump a region reference using blocks. + * Function: render_bin_output_region_blocks * - * Return: - * The function returns False if ERROR, otherwise True + * Purpose: Print some values from a dataset referenced by region blocks. + * This is a special case subfunction to dump a region reference using blocks. * + * Return: False if ERROR + * True otherwise *------------------------------------------------------------------------- */ hbool_t @@ -1629,7 +1543,7 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, hssize_t snblocks; hsize_t nblocks; hsize_t alloc_size; - hsize_t *ptdata; + hsize_t *ptdata = NULL; int sndims; unsigned ndims; hid_t dtype = -1; @@ -1675,8 +1589,7 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library + * Function: H5Tools Library * Purpose: Print the data values from a dataset referenced by region points. * * Description: @@ -1736,16 +1649,13 @@ render_bin_output_region_data_points(hid_t region_space, hid_t region_id, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print some values from a dataset referenced by region points. + * Function: render_bin_output_region_points * - * Description: - * This is a special case subfunction to dump a region reference using points. - * - * Return: - * The function returns False if the last dimension has been reached, otherwise True + * Purpose: Print some values from a dataset referenced by region points. + * This is a special case subfunction to dump a region reference using points. * + * Return: False if the last dimension has been reached + * True otherwise *------------------------------------------------------------------------- */ hbool_t @@ -1791,11 +1701,12 @@ CATCH } /*------------------------------------------------------------------------- - * Function: h5tools_is_zero + * Function: h5tools_is_zero * - * Purpose: Determines if memory is initialized to all zero bytes. + * Purpose: Determines if memory is initialized to all zero bytes. * - * Return: TRUE if all bytes are zero; FALSE otherwise + * Return: TRUE if all bytes are zero + * FALSE otherwise *------------------------------------------------------------------------- */ H5_ATTR_PURE hbool_t @@ -1811,23 +1722,20 @@ h5tools_is_zero(const void *_mem, size_t size) } /*------------------------------------------------------------------------- - * Function: h5tools_is_obj_same + * Function: h5tools_is_obj_same * - * Purpose: Check if two given object IDs or link names point to the same object. + * Purpose: Check if two given object IDs or link names point to the same object. * * Parameters: - * hid_t loc_id1: location of the first object - * char *name1: link name of the first object. - * Use "." or NULL if loc_id1 is the object to be compared. - * hid_t loc_id2: location of the second object - * char *name1: link name of the first object. - * Use "." or NULL if loc_id2 is the object to be compared. - * - * Return: TRUE if it is the same object; FALSE otherwise. + * hid_t loc_id1: location of the first object + * char *name1: link name of the first object. + * Use "." or NULL if loc_id1 is the object to be compared. + * hid_t loc_id2: location of the second object + * char *name1: link name of the first object. + * Use "." or NULL if loc_id2 is the object to be compared. * - * Programmer: Peter Cao - * 4/27/2011 - * + * Return: TRUE if it is the same object + * FALSE otherwise. *------------------------------------------------------------------------- */ hbool_t diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index f987296..ed7d38a 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -2888,7 +2888,7 @@ void h5tools_print_fill_value(h5tools_str_t *buffer/*in,out*/, const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, hid_t dcpl, hid_t type_id, hid_t obj_id) { size_t size; - hid_t n_type; + hid_t n_type = -1; void *buf = NULL; n_type = H5Tget_native_type(type_id, H5T_DIR_DEFAULT); @@ -3638,7 +3638,8 @@ h5tools_dump_attribute(FILE *stream, const h5tool_format_t *info, error_msg("unable to open attribute \"%s\"\n", attr_name); } else { - hid_t type, space; + hid_t type = -1; + hid_t space = -1; ctx->indent_level++; @@ -3857,9 +3858,9 @@ h5tools_dump_data(FILE *stream, const h5tool_format_t *info, H5S_class_t space_type; int ndims; int i; - hid_t space; - hid_t type; - hid_t p_type; + hid_t space = -1; + hid_t type = -1; + hid_t p_type = -1; hsize_t size[64]; hsize_t alloc_size; hsize_t nelmts = 1; diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index a66cfe5..a018394 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -715,10 +715,11 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai { size_t nsize, offset, size=0, nelmts, start; H5T_sign_t nsign; - char *name; + char *name = NULL; unsigned char *ucp_vp = (unsigned char *)vp; char *cp_vp = (char *)vp; - hid_t memb, obj; + hid_t memb = -1; + hid_t obj = -1; static char fmt_llong[8], fmt_ullong[8]; H5T_str_t pad; H5T_class_t type_class; @@ -1306,7 +1307,8 @@ void h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, void *vp) { - hid_t obj, region; + hid_t obj = -1; + hid_t region = -1; char ref_name[1024]; H5S_sel_type region_type; diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index a081c7e..5272e81 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -482,8 +482,7 @@ search_obj(table_t *table, haddr_t objno) *------------------------------------------------------------------------- */ static herr_t -find_objs_cb(const char *name, const H5O_info_t *oinfo, const char *already_seen, - void *op_data) +find_objs_cb(const char *name, const H5O_info_t *oinfo, const char *already_seen, void *op_data) { find_objs_t *info = (find_objs_t*)op_data; herr_t ret_value = 0; @@ -496,7 +495,7 @@ find_objs_cb(const char *name, const H5O_info_t *oinfo, const char *already_seen case H5O_TYPE_DATASET: if(NULL == already_seen) { - hid_t dset; + hid_t dset = -1; /* Add the dataset to the list of objects */ add_obj(info->dset_table, oinfo->addr, name, TRUE); diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c index 14b9461..c98575c 100644 --- a/tools/src/h5repack/h5repack.c +++ b/tools/src/h5repack/h5repack.c @@ -374,7 +374,7 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, if ((is_named = H5Tcommitted(ftype_id)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed"); if (is_named && travt) { - hid_t fidout; + hid_t fidout = -1; /* Create out file id */ if ((fidout = H5Iget_file_id(loc_out)) < 0) @@ -707,9 +707,9 @@ done: */ static int check_objects(const char* fname, pack_opt_t *options) { int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ - hid_t fid; - hid_t did; - hid_t sid; + hid_t fid = -1; + hid_t did = -1; + hid_t sid = -1; unsigned int i; unsigned int uf; trav_table_t *travt = NULL; diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index b043047..fa72cfe 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -1097,7 +1097,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, *------------------------------------------------------------------------- */ else { - hid_t pid; + hid_t pid = -1; /* create property to pass copy options */ if ((pid = H5Pcreate(H5P_OBJECT_COPY)) < 0) @@ -1435,51 +1435,51 @@ void print_user_block(const char *filename, hid_t fid) { int ret_value = 0; - int fh; /* file handle */ - hsize_t ub_size; /* user block size */ - hsize_t size; /* size read */ - hid_t fcpl; /* file creation property list ID for HDF5 file */ + hid_t fh = -1; /* file handle */ + hsize_t ub_size; /* user block size */ + hsize_t size; /* size read */ + hid_t fcpl = -1; /* file creation property list ID for HDF5 file */ int i; /* get user block size */ - if(( fcpl = H5Fget_create_plist(fid)) < 0) { + if ((fcpl = H5Fget_create_plist(fid)) < 0) { HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Fget_create_plist failed to retrieve file creation property list"); } - if(H5Pget_userblock(fcpl, &ub_size) < 0) { + if (H5Pget_userblock(fcpl, &ub_size) < 0) { HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pget_userblock failed to retrieve userblock size"); } - if(H5Pclose(fcpl) < 0) { + if (H5Pclose(fcpl) < 0) { HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed to close property list"); } /* open file */ - if((fh = HDopen(filename, O_RDONLY)) < 0) { + if ((fh = HDopen(filename, O_RDONLY)) < 0) { HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDopen failed to open file <%s>", filename); } size = ub_size; /* read file */ - while(size > 0) { + while (size > 0) { ssize_t nread; /* # of bytes read */ char rbuf[USERBLOCK_XFER_SIZE]; /* buffer for reading */ /* read buffer */ - if(size > USERBLOCK_XFER_SIZE) + if (size > USERBLOCK_XFER_SIZE) nread = HDread(fh, rbuf, (size_t)USERBLOCK_XFER_SIZE); else nread = HDread(fh, rbuf, (size_t)size); - for(i = 0; i < nread; i++) { + for (i = 0; i < nread; i++) { printf("%c ", rbuf[i]); } printf("\n"); - if(nread < 0) { + if (nread < 0) { HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "nread < 0"); } @@ -1488,7 +1488,7 @@ print_user_block(const char *filename, hid_t fid) } done: - if(fh > 0) + if (fh > 0) HDclose(fh); return; diff --git a/tools/src/h5repack/h5repack_refs.c b/tools/src/h5repack/h5repack_refs.c index 14294ea..7b610a3 100644 --- a/tools/src/h5repack/h5repack_refs.c +++ b/tools/src/h5repack/h5repack_refs.c @@ -145,7 +145,7 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if(H5Tequal(mtype_id, H5T_STD_REF_OBJ)) { - hid_t refobj_id; + hid_t refobj_id = -1; hobj_ref_t *refbuf = NULL; /* buffer for object references */ hobj_ref_t *buf = NULL; const char* refname; @@ -221,7 +221,7 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ else if(H5Tequal(mtype_id, H5T_STD_REF_DSETREG)) { - hid_t refobj_id; + hid_t refobj_id = -1; hdset_reg_ref_t *refbuf = NULL; /* input buffer for region references */ hdset_reg_ref_t *buf = NULL; /* output buffer */ const char* refname; @@ -260,7 +260,7 @@ int do_copy_refobjs(hid_t fidin, * in the second traversal of the file */ if((refname = MapIdToName(refobj_id, travt)) != NULL) { - hid_t region_id; /* region id of the referenced dataset */ + hid_t region_id = -1; /* region id of the referenced dataset */ if((region_id = H5Rget_region(dset_in, H5R_DATASET_REGION, &buf[u])) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed"); @@ -481,18 +481,16 @@ static int copy_refs_attr(hid_t loc_in, is_ref = (type_class == H5T_REFERENCE); if(type_class == H5T_VLEN ) { - hid_t base_type; + hid_t base_type = H5Tget_super(ftype_id); - base_type = H5Tget_super(ftype_id); is_ref_vlen = (H5Tget_class(base_type) == H5T_REFERENCE); msize = H5Tget_size(base_type); if (H5Tclose(base_type) < 0) H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed"); } else if(type_class == H5T_ARRAY ) { - hid_t base_type; + hid_t base_type = H5Tget_super(ftype_id); - base_type = H5Tget_super(ftype_id); is_ref_array = (H5Tget_class(base_type) == H5T_REFERENCE); msize = H5Tget_size(base_type); if (H5Tclose(base_type) < 0) @@ -573,9 +571,8 @@ static int copy_refs_attr(hid_t loc_in, unsigned array_rank = 0; hsize_t array_size = 1; hsize_t array_dims[H5S_MAX_RANK]; - hid_t base_type; + hid_t base_type = H5Tget_super(ftype_id); - base_type = H5Tget_super(ftype_id); msize = H5Tget_size(base_type); if (H5Tclose(base_type) < 0) H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed"); -- cgit v0.12