From 3b9e13a1b819584c91bfaa134536345a1460f44f Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 8 Nov 2018 11:27:22 -0600 Subject: TRILAB-82 fix coverity high-impact issues --- hl/tools/gif2h5/decompress.c | 2 +- tools/lib/h5diff.c | 8 +- tools/lib/h5tools.c | 32 +-- tools/lib/h5tools_dump.c | 88 +++---- tools/lib/h5tools_str.c | 58 ++--- tools/src/h5dump/h5dump_xml.c | 3 +- tools/src/h5import/h5import.c | 135 +++++------ tools/src/h5import/h5import.h | 4 +- tools/src/h5repack/h5repack_copy.c | 6 +- tools/src/h5repack/h5repack_main.c | 2 + tools/src/h5stat/h5stat.c | 68 +++--- tools/src/misc/h5clear.c | 33 +-- tools/test/h5format_convert/h5fc_gentest.c | 357 +++++++++++++++-------------- tools/test/h5jam/getub.c | 2 +- tools/test/h5repack/h5repack.sh.in | 1 + tools/test/h5repack/h5repacktst.c | 20 +- tools/test/h5stat/h5stat_gentest.c | 312 +++++++++++-------------- tools/test/h5stat/testh5stat.sh.in | 1 - tools/test/perform/zip_perf.c | 6 +- 19 files changed, 561 insertions(+), 577 deletions(-) diff --git a/hl/tools/gif2h5/decompress.c b/hl/tools/gif2h5/decompress.c index 453db12..6668c22 100644 --- a/hl/tools/gif2h5/decompress.c +++ b/hl/tools/gif2h5/decompress.c @@ -261,7 +261,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) * chain puts its associated output code on the output queue. */ while (CurCode > DataMask) { - if (OutCount > 1024) { + if (OutCount >= 1024) { /*return error message*/ } diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 28b1f00..594bf51 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -274,12 +274,15 @@ build_match_list (const char *objname1, trav_info_t *info1, const char *objname2 int cmp; trav_table_t *table = NULL; size_t idx; + int ret_value = 0; h5difftrace("build_match_list start\n"); /* init */ trav_table_init(&table); - if (table == NULL) - H5TOOLS_INFO(H5E_tools_min_id_g, "Cannot create tarverse table"); + if (table == NULL) { + H5TOOLS_INFO(H5E_tools_min_id_g, "Cannot create traverse table"); + HGOTO_DONE(-1); + } /* * This is necessary for the case that given objects are group and * have different names (ex: obj1 is /grp1 and obj2 is /grp5). @@ -367,6 +370,7 @@ build_match_list (const char *objname1, trav_info_t *info1, const char *objname2 free_exclude_path_list (opts); +done: *table_out = table; h5difftrace("build_match_list finish\n"); } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 470df63..d93f7b0 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -1241,10 +1241,10 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t H5T_class_t type_class; if((size = H5Tget_size(tid)) == 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed") if((type_class = H5Tget_class(tid)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed") switch (type_class) { case H5T_INTEGER: @@ -1264,7 +1264,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t bytes_wrote = HDfwrite(mem, 1, bytes_in, stream); if(bytes_wrote != bytes_in || (0 == bytes_wrote && HDferror(stream))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed") block_index -= (hsize_t)bytes_wrote; mem = mem + bytes_wrote; @@ -1287,7 +1287,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t if (s != NULL) size = HDstrlen(s); else - H5E_THROW(FAIL, H5E_tools_min_id_g, "NULL string"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "NULL string") } else { s = (char *) mem; @@ -1295,7 +1295,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); if (1 != HDfwrite(&tempuchar, sizeof(unsigned char), 1, stream)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed") } /* i */ } /* for (block_index = 0; block_index < block_nelmts; block_index++) */ } @@ -1306,7 +1306,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t unsigned nmembs; if((snmembs = H5Tget_nmembers(tid)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers of compound failed"); + 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++) { @@ -1322,7 +1322,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t 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"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output of compound member failed") } H5Tclose(memb); @@ -1350,7 +1350,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t } else { H5Tclose(memb); - H5E_THROW(FAIL, H5E_tools_min_id_g, "calculate the number of array elements failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "calculate the number of array elements failed") } for (block_index = 0; block_index < block_nelmts; block_index++) { @@ -1358,7 +1358,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t /* dump the array element */ if (render_bin_output(stream, container, memb, mem, nelmts) < 0) { H5Tclose(memb); - H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed") } } H5Tclose(memb); @@ -1380,7 +1380,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t /* dump the array element */ 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"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed") } } H5Tclose(memb); @@ -1426,7 +1426,7 @@ 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; if (size != HDfwrite(mem, sizeof(char), size, stream)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed") } /* end for */ break; @@ -1434,7 +1434,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t case H5T_NCLASSES: default: /* Badness */ - H5E_THROW(FAIL, H5E_tools_min_id_g, "bad type class"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "bad type class") break; } /* end switch */ @@ -1562,12 +1562,12 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, hid_t type_id = -1; if((snblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0) - H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed"); + H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed") nblocks = (hsize_t)snblocks; /* Print block information */ if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) - H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed") ndims = (unsigned)sndims; alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); @@ -1683,12 +1683,12 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id, hid_t type_id = -1; if((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0) - H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed") npoints = (hsize_t)snpoints; /* Allocate space for the dimension array */ if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) - H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed") ndims = (unsigned)sndims; if((dtype = H5Dget_type(region_id)) < 0) diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index 69cecb0..a8b7e30 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -618,12 +618,12 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, HDassert(buffer); if((snblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed"); + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed") nblocks = (hsize_t)snblocks; /* Print block information */ if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed") ndims = (unsigned)sndims; /* Render the region { element begin */ @@ -944,12 +944,12 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, HDassert(buffer); if((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed") npoints = (hsize_t)snpoints; /* Allocate space for the dimension array */ if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed") ndims = (unsigned)sndims; /* Render the region { element begin */ @@ -1156,7 +1156,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c unsigned int vl_data = 0; /* contains VL datatypes */ if ((size_t) ctx->ndims > NELMTS(sm_size)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "ndims and sm_size comparision failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "ndims and sm_size comparision failed") if (ctx->ndims > 0) init_acc_pos(ctx, total_size); @@ -1184,10 +1184,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) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed") if((ssm_nelmts = H5Sget_select_npoints(f_space)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed") sm_nelmts = (hsize_t)ssm_nelmts; if (sm_nelmts > 0) { @@ -1196,7 +1196,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) - H5E_THROW(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) { @@ -1210,17 +1210,17 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c HDassert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/ if(NULL == (sm_buf = (unsigned char *)HDmalloc((size_t) sm_nelmts * p_type_nbytes))) - H5E_THROW(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) - H5E_THROW(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) - H5E_THROW(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) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed") /* print the data */ flags = START_OF_DATA; @@ -1234,7 +1234,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) - H5E_THROW(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++) { @@ -1259,13 +1259,13 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); if(H5Sclose(sm_space) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed") if(sm_buf) HDfree(sm_buf); sm_buf = NULL; } else - H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print"); + H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print") ctx->continuation++; @@ -1462,10 +1462,10 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_co hsize_t total_size[H5S_MAX_RANK];/* total size of dataset*/ if((f_space = H5Dget_space(dset)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed") if((sndims = H5Sget_simple_extent_ndims(f_space)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed") ctx->ndims = (unsigned)sndims; /* assume entire data space to be printed */ @@ -1474,7 +1474,7 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_co ctx->p_min_idx[i] = 0; if(H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0) - H5E_THROW(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]; /* Set the compound datatype field list for display */ @@ -1484,7 +1484,7 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_co CATCH if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed") return ret_value; } @@ -1540,15 +1540,15 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_cont f_space = H5Dget_space(dset); if (f_space == FAIL) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed") sndims = H5Sget_simple_extent_ndims(f_space); if(sndims < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed") ctx->ndims = (unsigned)sndims; if ((size_t)ctx->ndims > NELMTS(sm_size)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(sm_size) failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(sm_size) failed") /* Assume entire data space to be printed */ if (ctx->ndims > 0) @@ -1629,7 +1629,7 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_cont /* Read the data */ if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) { - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed") } /* Print the data */ @@ -1667,9 +1667,9 @@ CATCH done: if(sm_space >= 0 && H5Sclose(sm_space) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed") if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed") return ret_value; } @@ -1696,11 +1696,11 @@ h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_conte sndims = H5Sget_simple_extent_ndims(space); if(sndims < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed") ctx->ndims = (unsigned)sndims; if ((size_t) ctx->ndims > NELMTS(ctx->p_min_idx)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(ctx->p_min_idx) failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(ctx->p_min_idx) failed") /* Assume entire data space to be printed */ for (i = 0; i < ctx->ndims; i++) @@ -1900,7 +1900,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ const char *order_s = NULL; /* byte order string */ if((type_class = H5Tget_class(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed") if (object_search && H5Tcommitted(type) > 0) { H5O_info_t oinfo; obj_t *obj = NULL; /* Found object */ @@ -2280,7 +2280,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ char *ttag; if(NULL == (ttag = H5Tget_tag(type))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_tag failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_tag failed") ctx->need_prefix = TRUE; @@ -2300,7 +2300,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ case H5T_COMPOUND: if((snmembers = H5Tget_nmembers(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed") nmembers = (unsigned)snmembers; h5tools_str_append(buffer, "H5T_COMPOUND %s", h5tools_dump_header_format->structblockbegin); @@ -2344,7 +2344,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ case H5T_ENUM: if((super = H5Tget_super(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed") h5tools_str_append(buffer, "H5T_ENUM %s", h5tools_dump_header_format->enumblockbegin); h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); @@ -2374,14 +2374,14 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ case H5T_VLEN: if((super = H5Tget_super(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed") h5tools_str_append(buffer, "H5T_VLEN %s ", h5tools_dump_header_format->vlenblockbegin); h5tools_print_datatype(stream, buffer, info, ctx, super, TRUE); if(H5Tclose(super) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed") h5tools_str_append(buffer, "%s", h5tools_dump_header_format->vlenblockend); @@ -2456,10 +2456,10 @@ h5tools_print_dataspace(h5tools_str_t *buffer, hid_t space) int i; if((ndims = H5Sget_simple_extent_dims(space, size, maxsize)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed") if((space_type = H5Sget_simple_extent_type(space)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_type failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_type failed") switch(space_type) { case H5S_SCALAR: @@ -2544,15 +2544,15 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i ncols = info->line_ncols; if((snmembs = H5Tget_nmembers(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed") nmembs = (unsigned)snmembs; HDassert(nmembs > 0); if((super = H5Tget_super(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed") if((type_size = H5Tget_size(type)) <= 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size(type) failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size(type) failed") /* * Determine what datatype to use for the native values. To simplify @@ -2565,7 +2565,7 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i dst_size = sizeof(long long); if((sign_type = H5Tget_sign(type))<0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_sign failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_sign failed") if(H5T_SGN_NONE == sign_type) native = H5T_NATIVE_ULLONG; else @@ -2576,20 +2576,20 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i /* Get the names and raw values of all members */ if(NULL == (name = (char **)HDcalloc((size_t)nmembs, sizeof(char *)))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member name"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member name") if(NULL == (value = (unsigned char *)HDcalloc((size_t)nmembs, MAX(type_size, dst_size)))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member value"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member value") for (i = 0; i < nmembs; i++) { name[i] = H5Tget_member_name(type, i); if(H5Tget_member_value(type, i, value + i * type_size) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_member_value failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_member_value failed") } /* Convert values to native datatype */ if (native > 0) if(H5Tconvert(super, native, (size_t)nmembs, value, NULL, H5P_DEFAULT) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tconvert failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tconvert failed") /* * Sort members by increasing value @@ -2646,7 +2646,7 @@ CATCH HDfree(value); if(super >= 0 && H5Tclose(super) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not close datatype's super class"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not close datatype's super class") if(0 == nmembs) h5tools_str_append(buffer, "\n"); diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 3d595ca..3e8f1fe 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -1045,43 +1045,47 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } else { - unsigned nmembs; - unsigned j; + int retvalue; - nmembs = (unsigned)H5Tget_nmembers(type); - h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); + retvalue = H5Tget_nmembers(type); + if (retvalue >= 0) { + unsigned j; + unsigned nmembs = (unsigned)retvalue; - ctx->indent_level++; + h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); - for(j = 0; j < nmembs; j++) { - if(j) - h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", "OPTIONAL_LINE_BREAK)); - else - h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); + ctx->indent_level++; - if(info->arr_linebreak) - h5tools_str_indent(str, info, ctx); + for(j = 0; j < nmembs; j++) { + if(j) + h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", "OPTIONAL_LINE_BREAK)); + else + h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); - /* The name */ - name = H5Tget_member_name(type, j); - h5tools_str_append(str, OPT(info->cmpd_name, ""), name); - H5free_memory(name); + if(info->arr_linebreak) + h5tools_str_indent(str, info, ctx); - /* The value */ - offset = H5Tget_member_offset(type, j); - memb = H5Tget_member_type(type, j); + /* The name */ + name = H5Tget_member_name(type, j); + h5tools_str_append(str, OPT(info->cmpd_name, ""), name); + H5free_memory(name); - h5tools_str_sprint(str, info, container, memb, cp_vp + offset, ctx); + /* The value */ + offset = H5Tget_member_offset(type, j); + memb = H5Tget_member_type(type, j); - H5Tclose(memb); - } - ctx->indent_level--; + h5tools_str_sprint(str, info, container, memb, cp_vp + offset, ctx); - if(info->arr_linebreak) { - h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); - h5tools_str_indent(str, info, ctx); + H5Tclose(memb); + } + ctx->indent_level--; + + if(info->arr_linebreak) { + h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); + h5tools_str_indent(str, info, ctx); + } + h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}")); } - h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}")); } break; diff --git a/tools/src/h5dump/h5dump_xml.c b/tools/src/h5dump/h5dump_xml.c index e399d8f..ec76511 100644 --- a/tools/src/h5dump/h5dump_xml.c +++ b/tools/src/h5dump/h5dump_xml.c @@ -3438,8 +3438,7 @@ xml_dump_fill_value(hid_t dcpl, hid_t type) h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "\""); for (i = 0; i < sz; i++) { - h5tools_str_append(&buffer, "%x ", *(unsigned int *) buf); - buf = (char *) buf + sizeof(unsigned int); + h5tools_str_append(&buffer, "%x ", *(unsigned int *) buf + (i * sizeof(unsigned int))); } h5tools_str_append(&buffer, "\""); h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0); diff --git a/tools/src/h5import/h5import.c b/tools/src/h5import/h5import.c index 3b64a0e..16c0d8c 100644 --- a/tools/src/h5import/h5import.c +++ b/tools/src/h5import/h5import.c @@ -88,6 +88,7 @@ int main(int argc, char *argv[]) const char *err7 = "Invalid type of data - %s.\n"; const char *err8 = "Invalid size of data - %s.\n"; const char *err9 = "Cannot specify more than 30 input files in one call to h5import.\n"; + const char *err10 = "Length of output file name limited to 255 chars.\n"; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -98,6 +99,9 @@ int main(int argc, char *argv[]) (void) HDsetvbuf(stderr, (char *) NULL, _IOLBF, 0); (void) HDsetvbuf(stdout, (char *) NULL, _IOLBF, 0); + /* Initialize the file structure to 0 */ + HDmemset(&opt, 0, sizeof(struct Options)); + if (argv[1] && (HDstrcmp("-V", argv[1]) == 0)) { print_version(PROGRAMNAME); HDexit(EXIT_SUCCESS); @@ -112,9 +116,6 @@ int main(int argc, char *argv[]) goto err; } - /* Initialize the file structure to 0 */ - HDmemset(&opt, 0, sizeof(struct Options)); - /* * parse the command line */ @@ -155,6 +156,10 @@ int main(int argc, char *argv[]) break; case 5: /* get outfile found */ + if (HDstrlen(argv[i]) > MAX_PATH_NAME_LENGTH) { + (void) HDfprintf(stderr, err10, argv[i]); + goto err; + } (void) HDstrcpy(opt.outfile, argv[i]); outfile_named = TRUE; break; @@ -1366,9 +1371,9 @@ static int allocateFloatStorage(struct Input *in) static int processConfigurationFile(char *infile, struct Input *in) { FILE *strm = NULL; - char key[255]; + char key[MAX_PATH_NAME_LENGTH]; int kindex; - char temp[255]; + char temp[MAX_PATH_NAME_LENGTH]; int ival; int scanret; int retval = -1; @@ -1446,16 +1451,16 @@ static int processConfigurationFile(char *infile, struct Input *in) goto error; } - scanret = fscanf(strm, "%s", key); + scanret = fscanf(strm, "%254s", key); if((scanret == 1) && !HDstrcmp("HDF5", key)) { #ifdef H5DEBUGIMPORT int pndx; HDprintf("\nh5dump file\n"); #endif in->h5dumpInput = 1; - scanret = fscanf(strm, "%s", temp); /* filename */ - scanret = fscanf(strm, "%s", temp); /* start bracket */ - scanret = fscanf(strm, "%s", key); /* DATASET */ + scanret = fscanf(strm, "%254s", temp); /* filename */ + scanret = fscanf(strm, "%254s", temp); /* start bracket */ + scanret = fscanf(strm, "%254s", key); /* DATASET */ while (scanret == 1) { if(!HDstrcmp("DATASET", key)) { /* PATH */ #ifdef H5DEBUGIMPORT @@ -1465,7 +1470,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, err3a, infile); goto error; } - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1477,7 +1482,7 @@ static int processConfigurationFile(char *infile, struct Input *in) goto error; } in->configOptionVector[PATH] = 1; - scanret = fscanf(strm, "%s", temp); /* start bracket */ + scanret = fscanf(strm, "%254s", temp); /* start bracket */ #ifdef H5DEBUGIMPORT HDprintf("h5dump DATASET %s found\n", temp); #endif @@ -1491,7 +1496,7 @@ static int processConfigurationFile(char *infile, struct Input *in) goto error; } - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1528,20 +1533,20 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump DATATYPE STRING found\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* start bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* start bracket */ (void) HDfprintf(stderr, "%s", err18); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump DATATYPE STRING %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { /* string properties */ + if (fscanf(strm, "%254s", temp) != 1) { /* string properties */ (void) HDfprintf(stderr, "%s", err18); goto error; } while (get_next_prop) { if(!HDstrcmp("STRSIZE", temp)) { /* STRSIZE */ - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err19); goto error; } @@ -1561,7 +1566,7 @@ static int processConfigurationFile(char *infile, struct Input *in) } } else if(!HDstrcmp("STRPAD", temp)) { /* STRPAD */ - if (fscanf(strm, "%s", temp) != 1) { /* STRPAD type */ + if (fscanf(strm, "%254s", temp) != 1) { /* STRPAD type */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1570,7 +1575,7 @@ static int processConfigurationFile(char *infile, struct Input *in) #endif } else if(!HDstrcmp("CSET", key)) { /* CSET */ - if (fscanf(strm, "%s", temp) != 1) { /* CSET type */ + if (fscanf(strm, "%254s", temp) != 1) { /* CSET type */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1580,7 +1585,7 @@ static int processConfigurationFile(char *infile, struct Input *in) } else if(!HDstrcmp("CTYPE", temp)) { /* CTYPE */ - if (fscanf(strm, "%s", temp) != 1) { /* CTYPE type */ + if (fscanf(strm, "%254s", temp) != 1) { /* CTYPE type */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1588,7 +1593,7 @@ static int processConfigurationFile(char *infile, struct Input *in) HDprintf("h5dump DATATYPE STRING CTYPE %s found\n", temp); #endif } /* if(!HDstrcmp("CSET", key)) */ - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1607,7 +1612,7 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump DATASPACE key\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1623,14 +1628,14 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump DATASPACE SIMPLE found\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* start bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* start bracket */ (void) HDfprintf(stderr, err6b, infile); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump DATASPACE SIMPLE %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { /* start paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* start paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1641,7 +1646,7 @@ static int processConfigurationFile(char *infile, struct Input *in) int get_next_dim = 1; int i = 0; - if (fscanf(strm, "%s", temp) != 1) { /* Dimension with optional comma */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension with optional comma */ (void) HDfprintf(stderr, err16c, infile); goto error; } @@ -1651,7 +1656,7 @@ static int processConfigurationFile(char *infile, struct Input *in) while (get_next_dim) { char *more = temp; temp_dims[icount] = HDstrtoull(more, &more, 10); - if (fscanf(strm, "%s", temp) != 1) { /* Dimension or end paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension or end paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1694,7 +1699,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, err5b, infile); goto error; } - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1705,7 +1710,7 @@ static int processConfigurationFile(char *infile, struct Input *in) if ((in->maxsizeOfDimension = (hsize_t *) HDmalloc ((size_t) in->rank * sizeof(hsize_t))) == NULL) { goto error; } - if (fscanf(strm, "%s", temp) != 1) { /* start paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* start paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1719,7 +1724,7 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump DATASPACE SIMPLE process max dim values\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* max dim with optional comma */ + if (fscanf(strm, "%254s", temp) != 1) { /* max dim with optional comma */ (void) HDfprintf(stderr, err16c, infile); goto error; } @@ -1738,7 +1743,7 @@ static int processConfigurationFile(char *infile, struct Input *in) char *more = temp; in->maxsizeOfDimension[i] = HDstrtoull(more, &more, 10); } - if (fscanf(strm, "%s", temp) != 1) { /* max dim or end paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* max dim or end paren */ (void) HDfprintf(stderr, err16c, infile); goto error; } @@ -1750,7 +1755,7 @@ static int processConfigurationFile(char *infile, struct Input *in) } else { /* comma */ i++; - if (i > MAX_NUM_DIMENSION) { + if (i >= MAX_NUM_DIMENSION) { (void) HDfprintf(stderr, "Invalid value for rank.\n"); goto error; } @@ -1769,7 +1774,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, err16c, infile); goto error; } - scanret = fscanf(strm, "%s", temp); /* end bracket */ + scanret = fscanf(strm, "%254s", temp); /* end bracket */ #ifdef H5DEBUGIMPORT HDprintf("h5dump DATASPACE SIMPLE %s found\n", temp); #endif @@ -1784,14 +1789,14 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump STORAGE_LAYOUT key\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* start bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* start bracket */ (void) HDfprintf(stderr, err6b, infile); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump STORAGE_LAYOUT %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { /* CHUNKED */ + if (fscanf(strm, "%254s", temp) != 1) { /* CHUNKED */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1803,7 +1808,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, "Unable to allocate dynamic memory.\n"); goto error; } - if (fscanf(strm, "%s", temp) != 1) { /* start paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* start paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1814,7 +1819,7 @@ static int processConfigurationFile(char *infile, struct Input *in) int get_next_dim = 1; int icount = 0; - if (fscanf(strm, "%s", temp) != 1) { /* Dimension with optional comma */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension with optional comma */ (void) HDfprintf(stderr, err16c, infile); goto error; } @@ -1824,7 +1829,7 @@ static int processConfigurationFile(char *infile, struct Input *in) while (get_next_dim) { char *more = temp; in->sizeOfChunk[icount] = HDstrtoull(more, &more, 10); - if (fscanf(strm, "%s", temp) != 1) { /* Dimension or end paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension or end paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1856,7 +1861,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, err5b, infile); goto error; } - if (fscanf(strm, "%s", temp) != 1) { /* SIZE */ + if (fscanf(strm, "%254s", temp) != 1) { /* SIZE */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1873,7 +1878,7 @@ static int processConfigurationFile(char *infile, struct Input *in) #endif } while (HDstrcmp("}", temp)) { - if (fscanf(strm, "%s", temp) != 1) { /* end bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* end bracket */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1888,14 +1893,14 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump FILTERS key\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* start bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* start bracket */ (void) HDfprintf(stderr, err6b, infile); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump FILTERS %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1906,21 +1911,21 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump FILTERS COMPRESSION found\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* DEFLATE */ + if (fscanf(strm, "%254s", temp) != 1) { /* DEFLATE */ (void) HDfprintf(stderr, "%s", err18); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump FILTERS COMPRESSION %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { /* bgin bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* bgin bracket */ (void) HDfprintf(stderr, "%s", err18); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump FILTERS COMPRESSION %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { /* LEVEL */ + if (fscanf(strm, "%254s", temp) != 1) { /* LEVEL */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1935,7 +1940,7 @@ static int processConfigurationFile(char *infile, struct Input *in) HDprintf("h5dump FILTERS COMPRESSION LEVEL %d found\n", ival); #endif in->compressionParam = ival; - if (fscanf(strm, "%s", temp) != 1) { /* end bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* end bracket */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1957,7 +1962,7 @@ static int processConfigurationFile(char *infile, struct Input *in) #endif in->configOptionVector[COMPRESS] = 0; } - if (fscanf(strm, "%s", temp) != 1) { /* end bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* end bracket */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1971,14 +1976,14 @@ static int processConfigurationFile(char *infile, struct Input *in) #ifdef H5DEBUGIMPORT HDprintf("h5dump SUBSET key\n"); #endif - if (fscanf(strm, "%s", temp) != 1) { /* start bracket */ + if (fscanf(strm, "%254s", temp) != 1) { /* start bracket */ (void) HDfprintf(stderr, err20, infile); goto error; } #ifdef H5DEBUGIMPORT HDprintf("h5dump SUBSET %s found\n", temp); #endif - if (fscanf(strm, "%s", temp) != 1) { /* SUBSET keyword */ + if (fscanf(strm, "%254s", temp) != 1) { /* SUBSET keyword */ (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -1988,7 +1993,7 @@ static int processConfigurationFile(char *infile, struct Input *in) while (get_next_prop) { if(!HDstrcmp("COUNT", temp)) { /* COUNT */ int icount = 0; - if (fscanf(strm, "%s", temp) != 1) { /* start paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* start paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -1999,7 +2004,7 @@ static int processConfigurationFile(char *infile, struct Input *in) int get_next_dim = 1; int i = 0; - if (fscanf(strm, "%s", temp) != 1) { /* Dimension with optional comma */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension with optional comma */ (void) HDfprintf(stderr, err16c, infile); goto error; } @@ -2009,7 +2014,7 @@ static int processConfigurationFile(char *infile, struct Input *in) while (get_next_dim) { char *more = temp; temp_dims[icount] = HDstrtoull(more, &more, 10); - if (fscanf(strm, "%s", temp) != 1) { /* Dimension or end paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension or end paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -2023,7 +2028,7 @@ static int processConfigurationFile(char *infile, struct Input *in) } else { /* Dimension */ icount++; - if (icount > MAX_NUM_DIMENSION) { + if (icount >= MAX_NUM_DIMENSION) { (void) HDfprintf(stderr, "Invalid value for rank.\n"); goto error; } @@ -2044,7 +2049,7 @@ static int processConfigurationFile(char *infile, struct Input *in) } /* if(!HDstrcmp("COUNT", temp)) COUNT */ if(!HDstrcmp("BLOCK", temp)) { /* BLOCK */ int icount = 0; - if (fscanf(strm, "%s", temp) != 1) { /* start paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* start paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -2055,7 +2060,7 @@ static int processConfigurationFile(char *infile, struct Input *in) int get_next_dim = 1; int i = 0; - if (fscanf(strm, "%s", temp) != 1) { /* Dimension with optional comma */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension with optional comma */ (void) HDfprintf(stderr, err16c, infile); goto error; } @@ -2065,7 +2070,7 @@ static int processConfigurationFile(char *infile, struct Input *in) while (get_next_dim) { char *more = temp; temp_dims[icount] = HDstrtoull(more, &more, 10); - if (fscanf(strm, "%s", temp) != 1) { /* Dimension or end paren */ + if (fscanf(strm, "%254s", temp) != 1) { /* Dimension or end paren */ (void) HDfprintf(stderr, err6b, infile); goto error; } @@ -2098,7 +2103,7 @@ static int processConfigurationFile(char *infile, struct Input *in) in->configOptionVector[DIM] = 1; } /* if(!HDstrcmp("(", key)) start paren */ } /* if(!HDstrcmp("BLOCK", temp)) BLOCK */ - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -2117,7 +2122,7 @@ static int processConfigurationFile(char *infile, struct Input *in) scanret = 0; break; } - scanret = fscanf(strm, "%s", key); + scanret = fscanf(strm, "%254s", key); } #ifdef H5DEBUGIMPORT HDprintf("h5dump path"); @@ -2158,7 +2163,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, err3a, infile); goto error; } - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -2175,7 +2180,7 @@ static int processConfigurationFile(char *infile, struct Input *in) goto error; } - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err18); goto error; } @@ -2203,7 +2208,7 @@ static int processConfigurationFile(char *infile, struct Input *in) (void) HDfprintf(stderr, err5a, infile); goto error; } - if (fscanf(strm, "%d", (&ival)) != 1) { + if (fscanf(strm, "%254d", (&ival)) != 1) { (void) HDfprintf(stderr, "%s", err19); goto error; } @@ -2400,7 +2405,7 @@ static int processConfigurationFile(char *infile, struct Input *in) default: break; } - scanret = fscanf(strm, "%s", key); + scanret = fscanf(strm, "%254s", key); } /* @@ -2571,7 +2576,7 @@ static int getOutputClass(struct Input *in, FILE *strm) const char *err1 = "Unable to get 'string' value.\n"; const char *err2 = "Invalid value for output class.\n"; - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err1); return (-1); } @@ -3464,7 +3469,7 @@ static int getInputByteOrder(struct Input *in, FILE *strm) const char *err1 = "Unable to get 'string' value.\n"; const char *err2 = "Invalid value for input byte-order.\n"; - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err1); return (-1); } @@ -3595,7 +3600,7 @@ static int getOutputArchitecture(struct Input *in, FILE *strm) const char *err1 = "Unable to get 'string' value.\n"; const char *err2 = "Invalid value for output architecture.\n"; - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err1); return (-1); } @@ -3627,7 +3632,7 @@ static int getOutputByteOrder(struct Input *in, FILE *strm) const char *err1 = "Unable to get 'string' value.\n"; const char *err2 = "Invalid value for output byte-order.\n"; - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err1); return (-1); } @@ -3658,7 +3663,7 @@ static int getCompressionType(struct Input *in, FILE *strm) const char *err1 = "Unable to get 'string' value.\n"; const char *err2 = "Invalid value for compression.\n"; - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err1); return (-1); } @@ -3722,7 +3727,7 @@ static int getExternalFilename(struct Input *in, FILE *strm) char temp[255]; const char *err1 = "Unable to get 'string' value.\n"; - if (fscanf(strm, "%s", temp) != 1) { + if (fscanf(strm, "%254s", temp) != 1) { (void) HDfprintf(stderr, "%s", err1); return (-1); } diff --git a/tools/src/h5import/h5import.h b/tools/src/h5import/h5import.h index c55717d..00c41f6 100644 --- a/tools/src/h5import/h5import.h +++ b/tools/src/h5import/h5import.h @@ -102,8 +102,8 @@ struct Input struct infilesformat { - char datafile[255]; - char configfile[255]; + char datafile[MAX_PATH_NAME_LENGTH]; + char configfile[MAX_PATH_NAME_LENGTH]; struct Input in; int config; /* Configfile present? No - 0. Yes - 1 */ }; diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index b279cf9..0567269 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -1422,9 +1422,9 @@ copy_user_block(const char *infile, const char *outfile, hsize_t size) } /* end while */ done: - if (infid > 0) + if (infid >= 0) HDclose(infid); - if (outfid > 0) + if (outfid >= 0) HDclose(outfid); return ret_value; @@ -1497,7 +1497,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_main.c b/tools/src/h5repack/h5repack_main.c index 8f0178f..dec25f9 100644 --- a/tools/src/h5repack/h5repack_main.c +++ b/tools/src/h5repack/h5repack_main.c @@ -707,6 +707,8 @@ int main(int argc, const char **argv) void *edata; void *tools_edata; + HDmemset(&options, 0, sizeof(pack_opt_t)); + h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); diff --git a/tools/src/h5stat/h5stat.c b/tools/src/h5stat/h5stat.c index dc1dc4a..8109b93 100644 --- a/tools/src/h5stat/h5stat.c +++ b/tools/src/h5stat/h5stat.c @@ -74,7 +74,7 @@ typedef struct iter_t { ohdr_info_t group_ohdr_info; /* Object header information for groups */ hsize_t max_attrs; /* Maximum attributes from a group */ - unsigned long *num_small_attrs; /* Size of small attributes tracked */ + unsigned long *num_small_attrs; /* Size of small attributes tracked */ unsigned attr_nbins; /* Number of bins for attribute counts */ unsigned long *attr_bins; /* Pointer to array of bins for attribute counts */ @@ -257,7 +257,7 @@ leave(int ret) } - + /*------------------------------------------------------------------------- * Function: usage * @@ -297,7 +297,7 @@ static void usage(const char *prog) HDfprintf(stdout, " --enable-error-stack Prints messages from the HDF5 error stack as they occur\n"); } - + /*------------------------------------------------------------------------- * Function: ceil_log10 * @@ -324,7 +324,7 @@ ceil_log10(unsigned long x) return ret; } /* ceil_log10() */ - + /*------------------------------------------------------------------------- * Function: attribute_stats * @@ -374,7 +374,7 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi) return 0; } /* end attribute_stats() */ - + /*------------------------------------------------------------------------- * Function: group_stats * @@ -456,7 +456,7 @@ done: return ret_value; } /* end group_stats() */ - + /*------------------------------------------------------------------------- * Function: dataset_stats * @@ -648,7 +648,7 @@ done: return ret_value; } /* end dataset_stats() */ - + /*------------------------------------------------------------------------- * Function: datatype_stats * @@ -680,7 +680,7 @@ done: return ret_value; } /* end datatype_stats() */ - + /*------------------------------------------------------------------------- * Function: obj_stats * @@ -736,7 +736,7 @@ done: return ret_value; } /* end obj_stats() */ - + /*------------------------------------------------------------------------- * Function: lnk_stats * @@ -834,7 +834,7 @@ freespace_stats(hid_t fid, iter_t *iter) return 0; } /* end freespace_stats() */ - + /*------------------------------------------------------------------------- * Function: hand_free * @@ -863,7 +863,7 @@ hand_free(struct handler_t *hand) } /* end if */ } /* end hand_free() */ - + /*------------------------------------------------------------------------- * Function: parse_command_line * @@ -1041,7 +1041,7 @@ error: return -1; } - + /*------------------------------------------------------------------------- * Function: iter_free * @@ -1106,7 +1106,7 @@ iter_free(iter_t *iter) } /* end if */ } /* end iter_free() */ - + /*------------------------------------------------------------------------- * Function: print_file_info * @@ -1138,7 +1138,7 @@ print_file_info(const iter_t *iter) return 0; } /* print_file_info() */ - + /*------------------------------------------------------------------------- * Function: print_file_metadata * @@ -1198,7 +1198,7 @@ print_file_metadata(const iter_t *iter) return 0; } /* print_file_metadata() */ - + /*------------------------------------------------------------------------- * Function: print_group_info * @@ -1255,7 +1255,7 @@ print_group_info(const iter_t *iter) return 0; } /* print_group_info() */ - + /*------------------------------------------------------------------------- * Function: print_group_metadata * @@ -1282,7 +1282,7 @@ print_group_metadata(const iter_t *iter) return 0; } /* print_group_metadata() */ - + /*------------------------------------------------------------------------- * Function: print_dataset_info * @@ -1369,7 +1369,7 @@ print_dataset_info(const iter_t *iter) return 0; } /* print_dataset_info() */ - + /*------------------------------------------------------------------------- * Function: print_dataset_metadata * @@ -1398,7 +1398,7 @@ print_dset_metadata(const iter_t *iter) return 0; } /* print_dset_metadata() */ - + /*------------------------------------------------------------------------- * Function: print_dset_dtype_meta * @@ -1439,7 +1439,7 @@ print_dset_dtype_meta(const iter_t *iter) return 0; } /* print_dset_dtype_meta() */ - + /*------------------------------------------------------------------------- * Function: print_attr_info * @@ -1488,7 +1488,7 @@ print_attr_info(const iter_t *iter) return 0; } /* print_attr_info() */ - + /*------------------------------------------------------------------------- * Function: print_freespace_info * @@ -1538,7 +1538,7 @@ print_freespace_info(const iter_t *iter) return 0; } /* print_freespace_info() */ - + /*------------------------------------------------------------------------- * Function: print_storage_summary * @@ -1602,7 +1602,7 @@ print_storage_summary(const iter_t *iter) return 0; } /* print_storage_summary() */ - + /*------------------------------------------------------------------------- * Function: print_file_statistics * @@ -1649,7 +1649,7 @@ print_file_statistics(const iter_t *iter) if(display_summary) print_storage_summary(iter); } /* print_file_statistics() */ - + /*------------------------------------------------------------------------- * Function: print_object_statistics * @@ -1672,7 +1672,7 @@ print_object_statistics(const char *name) printf("Object name %s\n", name); } /* print_object_statistics() */ - + /*------------------------------------------------------------------------- * Function: print_statistics * @@ -1698,7 +1698,7 @@ print_statistics(const char *name, const iter_t *iter) print_file_statistics(iter); } /* print_statistics() */ - + /*------------------------------------------------------------------------- * Function: main * @@ -1780,15 +1780,15 @@ main(int argc, const char *argv[]) iter.free_hdr = finfo.free.meta_size; } /* end else */ - iter.num_small_groups = (unsigned long *)HDcalloc((size_t)sgroups_threshold, sizeof(unsigned long)); - iter.num_small_attrs = (unsigned long *)HDcalloc((size_t)(sattrs_threshold+1), sizeof(unsigned long)); - iter.small_dset_dims = (unsigned long *)HDcalloc((size_t)sdsets_threshold, sizeof(unsigned long)); + iter.num_small_groups = (unsigned long *)HDcalloc((size_t)sgroups_threshold, sizeof(unsigned long)); + iter.num_small_attrs = (unsigned long *)HDcalloc((size_t)(sattrs_threshold+1), sizeof(unsigned long)); + iter.small_dset_dims = (unsigned long *)HDcalloc((size_t)sdsets_threshold, sizeof(unsigned long)); - if(iter.num_small_groups == NULL || iter.num_small_attrs == NULL || iter.small_dset_dims == NULL) { - error_msg("Unable to allocate memory for tracking small groups/datasets/attributes\n"); - h5tools_setstatus(EXIT_FAILURE); - goto done; - } + if(iter.num_small_groups == NULL || iter.num_small_attrs == NULL || iter.small_dset_dims == NULL) { + error_msg("Unable to allocate memory for tracking small groups/datasets/attributes\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; + } if((fcpl = H5Fget_create_plist(fid)) < 0) warn_msg("Unable to retrieve file creation property\n"); diff --git a/tools/src/misc/h5clear.c b/tools/src/misc/h5clear.c index 5724e1b..42dda92 100644 --- a/tools/src/misc/h5clear.c +++ b/tools/src/misc/h5clear.c @@ -170,9 +170,12 @@ parse_command_line(int argc, const char **argv) case 'i': increment_eoa_eof = TRUE; - if(opt_arg != NULL && (increment = HDatoi(opt_arg)) < 0) { - usage(h5tools_getprogname()); - goto done; + if(opt_arg != NULL) { + if (HDatoi(opt_arg) < 0) { + usage(h5tools_getprogname()); + goto done; + } + increment = HDatoi(opt_arg); } break; @@ -231,14 +234,14 @@ leave(int ret) * so the file is opened with write access. * The --filesize option just prints the EOA and EOF, so the file * is opened with read access. - * + * * The -s option will activate the private property: - * --H5F_ACS_CLEAR_STATUS_FLAGS_NAME + * --H5F_ACS_CLEAR_STATUS_FLAGS_NAME * The --increment option will active these two private properties: - * --H5F_ACS_NULL_FSM_ADDR_NAME - * --H5F_ACS_SKIP_EOF_CHECK_NAME + * --H5F_ACS_NULL_FSM_ADDR_NAME + * --H5F_ACS_SKIP_EOF_CHECK_NAME * The --filesize will activate the private property: - * --H5F_ACS_SKIP_EOF_CHECK_NAME + * --H5F_ACS_SKIP_EOF_CHECK_NAME * * Return: Success: 0 * Failure: 1 @@ -280,7 +283,7 @@ main (int argc, const char *argv[]) } /* Cannot combine the --filesize option with other options */ - if(print_filesize && + if(print_filesize && (clear_status_flags || remove_cache_image || increment_eoa_eof)) { error_msg("Cannot combine --filesize with other options\n"); h5tools_setstatus(EXIT_FAILURE); @@ -298,7 +301,7 @@ main (int argc, const char *argv[]) } /* -s option */ - if(clear_status_flags) { + if(clear_status_flags) { /* Set to clear the status_flags in the file's superblock */ /* Activate this private property */ if(H5Pset(fapl, H5F_ACS_CLEAR_STATUS_FLAGS_NAME, &clear_status_flags) < 0) { @@ -309,7 +312,7 @@ main (int argc, const char *argv[]) } /* --increment option */ - if(increment_eoa_eof) { + if(increment_eoa_eof) { /* Activate this private property */ if(H5Pset(fapl, H5F_ACS_SKIP_EOF_CHECK_NAME, &increment_eoa_eof) < 0) { error_msg("H5Pset\n"); @@ -325,7 +328,7 @@ main (int argc, const char *argv[]) } /* --filesize option; open the file read-only */ - if(print_filesize) { + if(print_filesize) { /* Activate this private property */ if(H5Pset(fapl, H5F_ACS_SKIP_EOF_CHECK_NAME, &print_filesize) < 0) { error_msg("H5Pset\n"); @@ -333,7 +336,7 @@ main (int argc, const char *argv[]) goto done; } flags = H5F_ACC_RDONLY; - } + } /* Open the file */ if((fid = h5tools_fopen(fname, flags, fapl, NULL, NULL, (size_t)0)) < 0) { @@ -367,7 +370,7 @@ main (int argc, const char *argv[]) } /* -m option */ - if(remove_cache_image) { + if(remove_cache_image) { if(H5Fget_mdc_image_info(fid, &image_addr, &image_len) < 0) { error_msg("H5Fget_mdc_image_info\n"); h5tools_setstatus(EXIT_FAILURE); @@ -375,7 +378,7 @@ main (int argc, const char *argv[]) } if(image_addr == HADDR_UNDEF && image_len == 0) warn_msg("No cache image in the file\n"); - } + } h5tools_setstatus(EXIT_SUCCESS); diff --git a/tools/test/h5format_convert/h5fc_gentest.c b/tools/test/h5format_convert/h5fc_gentest.c index 8c873be..b482dee 100644 --- a/tools/test/h5format_convert/h5fc_gentest.c +++ b/tools/test/h5format_convert/h5fc_gentest.c @@ -14,7 +14,7 @@ /* * Generate the binary hdf5 files for the h5format_convert tests. * Usage: just execute the program without any arguments will - * generate all the binary hdf5 files + * generate all the binary hdf5 files * * If you regenerate the test files (e.g., changing some code, * trying it on a new platform, ...), you need to verify the correctness @@ -24,71 +24,71 @@ #include "hdf5.h" #include "H5private.h" -#define NON_V3_FILE "h5fc_non_v3.h5" -#define EDGE_V3_FILE "h5fc_edge_v3.h5" -#define ERR_LEVEL_FILE "h5fc_err_level.h5" +#define NON_V3_FILE "h5fc_non_v3.h5" +#define EDGE_V3_FILE "h5fc_edge_v3.h5" +#define ERR_LEVEL_FILE "h5fc_err_level.h5" const char *FILENAME[] = { - "h5fc_ext1_i.h5", /* 0 */ - "h5fc_ext1_s.h5", /* 1 */ - "h5fc_ext1_f.h5", /* 2 */ - "h5fc_ext2_is.h5", /* 3 */ - "h5fc_ext2_if.h5", /* 4 */ - "h5fc_ext2_sf.h5", /* 5 */ - "h5fc_ext3_isf.h5", /* 6 */ - "h5fc_ext_none.h5", /* 7 */ + "h5fc_ext1_i.h5", /* 0 */ + "h5fc_ext1_s.h5", /* 1 */ + "h5fc_ext1_f.h5", /* 2 */ + "h5fc_ext2_is.h5", /* 3 */ + "h5fc_ext2_if.h5", /* 4 */ + "h5fc_ext2_sf.h5", /* 5 */ + "h5fc_ext3_isf.h5", /* 6 */ + "h5fc_ext_none.h5", /* 7 */ NULL }; -#define GROUP "GROUP" +#define GROUP "GROUP" -#define DSET_COMPACT "DSET_COMPACT" -#define DSET_CONTIGUOUS "DSET_CONTIGUOUS" +#define DSET_COMPACT "DSET_COMPACT" +#define DSET_CONTIGUOUS "DSET_CONTIGUOUS" -#define DSET_EA "DSET_EA" -#define DSET_NDATA_EA "DSET_NDATA_EA" -#define DSET_BT2 "DSET_BT2" -#define DSET_NDATA_BT2 "DSET_NDATA_BT2" -#define DSET_FA "DSET_FA" -#define DSET_NDATA_FA "DSET_NDATA_FA" -#define DSET_NONE "DSET_NONE" -#define DSET_NDATA_NONE "DSET_NDATA_NONE" +#define DSET_EA "DSET_EA" +#define DSET_NDATA_EA "DSET_NDATA_EA" +#define DSET_BT2 "DSET_BT2" +#define DSET_NDATA_BT2 "DSET_NDATA_BT2" +#define DSET_FA "DSET_FA" +#define DSET_NDATA_FA "DSET_NDATA_FA" +#define DSET_NONE "DSET_NONE" +#define DSET_NDATA_NONE "DSET_NDATA_NONE" -#define DSET_EDGE "DSET_EDGE" -#define DSET_ERR "DSET_ERR" +#define DSET_EDGE "DSET_EDGE" +#define DSET_ERR "DSET_ERR" #define ISTORE_IK 64 -#define ISTORE_ERR 1 +#define ISTORE_ERR 1 #define NUM 500 /* - * Function: gen_non() + * Function: gen_non() * * Create a file with SWMR write+non-latest-format--this will result in v3 superbock+latest version support: - * 1) 1 chunked dataset with extensible array chunk indexing type (without data) - * 2) 1 chunked dataset with version 2 B-tree chunk indexing type (with data) + * 1) 1 chunked dataset with extensible array chunk indexing type (without data) + * 2) 1 chunked dataset with version 2 B-tree chunk indexing type (with data) * Re-open the file with write+non-latest-format and create: - * 3) 1 chunked dataset with version 2 B-tree chunk indexing type (without data) - * 4) 1 chunked dataset with extensible array indexing type (with data) - * 5) 1 compact and 1 contiguous datasets + * 3) 1 chunked dataset with version 2 B-tree chunk indexing type (without data) + * 4) 1 chunked dataset with extensible array indexing type (with data) + * 5) 1 compact and 1 contiguous datasets */ static void gen_non(const char *fname) { - hid_t fid = -1; /* file id */ - hid_t fcpl = -1; /* file creation property list */ - hid_t gid = -1; /* group id */ - hid_t sid = -1; /* space id */ - hid_t dcpl = -1; /* dataset creation property id */ - hid_t did1 = -1, did2 = -1; /* dataset id */ - hsize_t dims1[1] = {10}; /* dataset dimension */ - hsize_t dims2[2] = {4, 6}; /* dataset dimension */ - hsize_t max_dims[2]; /* maximum dataset dimension */ - hsize_t c_dims[2] = {2, 3}; /* chunk dimension */ - int i; /* local index variable */ - int buf[24]; /* data buffer */ + hid_t fid = -1; /* file id */ + hid_t fcpl = -1; /* file creation property list */ + hid_t gid = -1; /* group id */ + hid_t sid = -1; /* space id */ + hid_t dcpl = -1; /* dataset creation property id */ + hid_t did1 = -1, did2 = -1; /* dataset id */ + hsize_t dims1[1] = {10}; /* dataset dimension */ + hsize_t dims2[2] = {4, 6}; /* dataset dimension */ + hsize_t max_dims[2]; /* maximum dataset dimension */ + hsize_t c_dims[2] = {2, 3}; /* chunk dimension */ + int i; /* local index variable */ + int buf[24]; /* data buffer */ if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) goto error; @@ -115,7 +115,7 @@ gen_non(const char *fname) if(H5Pset_chunk(dcpl, 2, c_dims) < 0) goto error; - /* + /* * Create a chunked dataset with extensible array chunk indexing type (without data) */ @@ -135,7 +135,7 @@ gen_non(const char *fname) if(H5Dclose(did1) < 0) goto error; - /* + /* * Create a chunked dataset with version 2 B-tree chunk indexing type (with data) */ @@ -226,7 +226,7 @@ gen_non(const char *fname) if(H5Dclose(did2) < 0) goto error; - /* + /* * Create a compact dataset in the group */ @@ -251,7 +251,7 @@ gen_non(const char *fname) if(H5Sclose(sid) < 0) goto error; - /* + /* * Create a contiguous dataset with (2d with data) in the file */ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) @@ -278,9 +278,9 @@ gen_non(const char *fname) goto error; if(H5Gclose(gid) < 0) - goto error; + goto error; if(H5Pclose(fcpl) < 0) - goto error; + goto error; if(H5Fclose(fid) < 0) goto error; @@ -298,24 +298,24 @@ error: } /* gen_non() */ /* - * Function: gen_edge() + * Function: gen_edge() * * Create a file with write+latest-format--this will result in v3 superblock+latest version support: - * A dataset: chunked, filtered, H5D_CHUNK_DONT_FILTER_PARTIAL_CHUNKS enabled - * (i.e. the dataset does not filter partial edge chunks) + * A dataset: chunked, filtered, H5D_CHUNK_DONT_FILTER_PARTIAL_CHUNKS enabled + * (i.e. the dataset does not filter partial edge chunks) */ static void gen_edge(const char *fname) { - hid_t fid = -1; /* file id */ - hid_t fapl = -1; /* file access property list */ - hid_t sid = -1; /* dataspace id */ - hid_t dcpl = -1; /* dataset creation property id */ - hid_t did = -1; /* dataset id */ - hsize_t dims2[2] = {12, 6}; /* Dataset dimensions */ - hsize_t c_dims[2] = {5, 5}; /* Chunk dimensions */ - float buf[12][6]; /* Buffer for writing data */ - int i, j; /* local index variable */ + hid_t fid = -1; /* file id */ + hid_t fapl = -1; /* file access property list */ + hid_t sid = -1; /* dataspace id */ + hid_t dcpl = -1; /* dataset creation property id */ + hid_t did = -1; /* dataset id */ + hsize_t dims2[2] = {12, 6}; /* Dataset dimensions */ + hsize_t c_dims[2] = {5, 5}; /* Chunk dimensions */ + float buf[12][6]; /* Buffer for writing data */ + int i, j; /* local index variable */ /* Create a new format file */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) @@ -377,37 +377,37 @@ error: /* - * Function: gen_err_level() + * Function: gen_err_level() * * Generate a file to test the situtation described in HDFFV-9434: - * Exceed the limit of v1-btree level + * Exceed the limit of v1-btree level * - * Create a file with H5Pset_istore_k(fcpl, 1). - * Create a chunked dataset with extensible array chunk index and - * appends many chunks to the dataset. + * Create a file with H5Pset_istore_k(fcpl, 1). + * Create a chunked dataset with extensible array chunk index and + * appends many chunks to the dataset. * - * When h5format_convert tries to convert the dataset with - * extensive array index in the file to v1-btree chunk index, - * it will insert the dataset chunks to the v1-btree chunk index. - * The tree will split quickly due to the 'K' value of 1 and the - * tree level will eventually hit the maximum: 2^8(256). + * When h5format_convert tries to convert the dataset with + * extensive array index in the file to v1-btree chunk index, + * it will insert the dataset chunks to the v1-btree chunk index. + * The tree will split quickly due to the 'K' value of 1 and the + * tree level will eventually hit the maximum: 2^8(256). */ static void gen_err_level(const char *fname) { - hid_t fid = -1; /* file ID */ - hid_t fapl = -1; /* file access property list */ - hid_t fcpl = -1; /* file creation property list */ - hid_t sid = -1; /* dataspace id */ - hid_t dcpl = -1; /* dataset creation property list */ - hid_t did = -1; /* dataset ID */ - hid_t fsid = -1; /* file dataspace ID */ - hid_t msid = -1; /* memory dataspace ID */ - unsigned char *buf = NULL; /* buffer for data */ - hsize_t dims[2] = {0, 1}; /* dataset dimension sizes */ - hsize_t max_dims[2] = {1, H5S_UNLIMITED}; /* dataset maximum dimension sizes */ - hsize_t chunk_dims[2] = {1, 1}; /* chunk dimension sizes */ - int n = 0; /* local index variable */ + hid_t fid = -1; /* file ID */ + hid_t fapl = -1; /* file access property list */ + hid_t fcpl = -1; /* file creation property list */ + hid_t sid = -1; /* dataspace id */ + hid_t dcpl = -1; /* dataset creation property list */ + hid_t did = -1; /* dataset ID */ + hid_t fsid = -1; /* file dataspace ID */ + hid_t msid = -1; /* memory dataspace ID */ + unsigned char *buf = NULL; /* buffer for data */ + hsize_t dims[2] = {0, 1}; /* dataset dimension sizes */ + hsize_t max_dims[2] = {1, H5S_UNLIMITED}; /* dataset maximum dimension sizes */ + hsize_t chunk_dims[2] = {1, 1}; /* chunk dimension sizes */ + int n = 0; /* local index variable */ /* Create a new format file */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) @@ -440,6 +440,8 @@ gen_err_level(const char *fname) goto error; /* Closing */ + if(H5Pclose(fcpl) < 0) + goto error; if(H5Pclose(dcpl) < 0) goto error; if(H5Sclose(sid) < 0) @@ -459,50 +461,51 @@ gen_err_level(const char *fname) /* Loop through appending 1 element at a time */ for(n = 0; n < NUM; n++) { - hsize_t start[2] = {0, 0}; - hsize_t count[2] = {1, 1}; - hsize_t extent[2] = {0, 0}; - - start[0] = 0; - start[1] = (hsize_t)n; - extent[0] = 1; - extent[1] = (hsize_t)(n + 1); - - /* Set current dimension sizes for the dataset */ - if(H5Dset_extent(did, extent) < 0) - goto error; - - /* Set up memory dataspace */ - if((msid = H5Screate_simple(2, count, NULL)) < 0) - goto error; - - /* Get file dataspace */ - if((fsid = H5Dget_space(did)) < 0) - goto error; - - if((H5Sselect_hyperslab(fsid, H5S_SELECT_SET, start, NULL, count, NULL)) < 0) - goto error; - - /* Write to the dataset */ - if(H5Dwrite(did, H5T_NATIVE_UCHAR, msid, fsid, H5P_DEFAULT, buf) < 0) - goto error; - - if(H5Sclose(fsid) < 0) - goto error; - if(H5Sclose(msid) < 0) - goto error; + hsize_t start[2] = {0, 0}; + hsize_t count[2] = {1, 1}; + hsize_t extent[2] = {0, 0}; + + start[0] = 0; + start[1] = (hsize_t)n; + extent[0] = 1; + extent[1] = (hsize_t)(n + 1); + + /* Set current dimension sizes for the dataset */ + if(H5Dset_extent(did, extent) < 0) + goto error; + + /* Set up memory dataspace */ + if((msid = H5Screate_simple(2, count, NULL)) < 0) + goto error; + + /* Get file dataspace */ + if((fsid = H5Dget_space(did)) < 0) + goto error; + + if((H5Sselect_hyperslab(fsid, H5S_SELECT_SET, start, NULL, count, NULL)) < 0) + goto error; + + /* Write to the dataset */ + if(H5Dwrite(did, H5T_NATIVE_UCHAR, msid, fsid, H5P_DEFAULT, buf) < 0) + goto error; + + if(H5Sclose(fsid) < 0) + goto error; + if(H5Sclose(msid) < 0) + goto error; } /* Closing */ if(H5Dclose(did) < 0) - goto error; + goto error; if(H5Fclose(fid) < 0) - goto error; + goto error; if(H5Pclose(fapl) < 0) - goto error; - if(buf) free(buf); + goto error; error: + if(buf) + free(buf); H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(sid); @@ -517,33 +520,33 @@ error: } /* gen_err_level() */ /* - * Function: gen_ext() + * Function: gen_ext() * * Create a file with/without latest format with: - * 1) 1 contiguous dataset (without data) - * 2) 2 chunked datasets with extensible array chunk indexing type (with/without data) - * 3) 2 chunked datasets with version 2 B-tree chunk indexing type (with/without data) - * 4) 2 chunked datasets with fixed array chunk indexing type (with/without data) - * 5) 2 chunked datasets with implicit array chunk indexing type (with/without data) + * 1) 1 contiguous dataset (without data) + * 2) 2 chunked datasets with extensible array chunk indexing type (with/without data) + * 3) 2 chunked datasets with version 2 B-tree chunk indexing type (with/without data) + * 4) 2 chunked datasets with fixed array chunk indexing type (with/without data) + * 5) 2 chunked datasets with implicit array chunk indexing type (with/without data) * It will create the file with/without messages in the superblock extension depending * on the parameter "what". */ static void gen_ext(const char *fname, unsigned new_format, unsigned what) { - hid_t fid = -1; /* file id */ - hid_t fapl = -1; /* file access property list */ - hid_t fcpl = -1; /* file creation property list */ - hid_t gid = -1; /* group id */ - hid_t sid = -1; /* space id */ - hid_t dcpl = -1; /* dataset creation property id */ - hid_t did1 = -1, did2 = -1; /* dataset id */ - hsize_t dims1[1] = {10}; /* dataset dimension */ - hsize_t dims2[2] = {4, 6}; /* dataset dimension */ - hsize_t max_dims[2]; /* maximum dataset dimension */ - hsize_t c_dims[2] = {2, 3}; /* chunk dimension */ - int i; /* local index variable */ - int buf[24]; /* data buffer */ + hid_t fid = -1; /* file id */ + hid_t fapl = -1; /* file access property list */ + hid_t fcpl = -1; /* file creation property list */ + hid_t gid = -1; /* group id */ + hid_t sid = -1; /* space id */ + hid_t dcpl = -1; /* dataset creation property id */ + hid_t did1 = -1, did2 = -1; /* dataset id */ + hsize_t dims1[1] = {10}; /* dataset dimension */ + hsize_t dims2[2] = {4, 6}; /* dataset dimension */ + hsize_t max_dims[2]; /* maximum dataset dimension */ + hsize_t c_dims[2] = {2, 3}; /* chunk dimension */ + int i; /* local index variable */ + int buf[24]; /* data buffer */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) goto error; @@ -559,34 +562,34 @@ gen_ext(const char *fname, unsigned new_format, unsigned what) /* Generate messages that might be placed in superblock extension */ switch(what) { - case 0: - H5Pset_istore_k(fcpl, ISTORE_IK); - break; - case 1: - H5Pset_shared_mesg_nindexes(fcpl, 4); - break; - case 2: - H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, FALSE, (hsize_t)1); - break; - case 3: - H5Pset_istore_k(fcpl, ISTORE_IK); - H5Pset_shared_mesg_nindexes(fcpl, 4); - break; - case 4: - H5Pset_istore_k(fcpl, ISTORE_IK); - H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, TRUE, (hsize_t)1); - break; - case 5: - H5Pset_shared_mesg_nindexes(fcpl, 4); - H5Pset_file_space_page_size(fcpl, (hsize_t)512); - break; - case 6: - H5Pset_istore_k(fcpl, ISTORE_IK); - H5Pset_shared_mesg_nindexes(fcpl, 4); - H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_NONE, FALSE, (hsize_t)1); - break; - default: - break; + case 0: + H5Pset_istore_k(fcpl, ISTORE_IK); + break; + case 1: + H5Pset_shared_mesg_nindexes(fcpl, 4); + break; + case 2: + H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, FALSE, (hsize_t)1); + break; + case 3: + H5Pset_istore_k(fcpl, ISTORE_IK); + H5Pset_shared_mesg_nindexes(fcpl, 4); + break; + case 4: + H5Pset_istore_k(fcpl, ISTORE_IK); + H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, TRUE, (hsize_t)1); + break; + case 5: + H5Pset_shared_mesg_nindexes(fcpl, 4); + H5Pset_file_space_page_size(fcpl, (hsize_t)512); + break; + case 6: + H5Pset_istore_k(fcpl, ISTORE_IK); + H5Pset_shared_mesg_nindexes(fcpl, 4); + H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_NONE, FALSE, (hsize_t)1); + break; + default: + break; } /* Create the file */ @@ -604,8 +607,8 @@ gen_ext(const char *fname, unsigned new_format, unsigned what) goto error; - /* - * Create a contiguous dataset + /* + * Create a contiguous dataset */ /* Create dataspace */ @@ -622,8 +625,8 @@ gen_ext(const char *fname, unsigned new_format, unsigned what) if(H5Dclose(did1) < 0) goto error; - /* - * Create 2 chunked datasets with extensible array chunk indexing type + /* + * Create 2 chunked datasets with extensible array chunk indexing type * (one with data; one without data) */ @@ -657,8 +660,8 @@ gen_ext(const char *fname, unsigned new_format, unsigned what) goto error; - /* - * Create 2 chunked datasets with version 2 B-tree chunk indexing type + /* + * Create 2 chunked datasets with version 2 B-tree chunk indexing type * (one with data; one without data) */ @@ -689,7 +692,7 @@ gen_ext(const char *fname, unsigned new_format, unsigned what) goto error; /* - * Create 2 chunked datasets with fixed array chunk indexing type + * Create 2 chunked datasets with fixed array chunk indexing type * (one with data; one without data) */ @@ -719,8 +722,8 @@ gen_ext(const char *fname, unsigned new_format, unsigned what) goto error; - /* - * Create 2 chunked datasets with implicit chunk indexing type + /* + * Create 2 chunked datasets with implicit chunk indexing type * (one with data; one without data) */ diff --git a/tools/test/h5jam/getub.c b/tools/test/h5jam/getub.c index 7cfde36..26a427d 100644 --- a/tools/test/h5jam/getub.c +++ b/tools/test/h5jam/getub.c @@ -148,7 +148,7 @@ main(int argc, const char *argv[]) error: if(buf) HDfree(buf); - if(fd > -1) + if(fd >= 0) HDclose(fd); return EXIT_FAILURE; } /* end main() */ diff --git a/tools/test/h5repack/h5repack.sh.in b/tools/test/h5repack/h5repack.sh.in index b0a2f99..a36eb08 100644 --- a/tools/test/h5repack/h5repack.sh.in +++ b/tools/test/h5repack/h5repack.sh.in @@ -997,6 +997,7 @@ fi ############################################################################## ### T H E T E S T S ############################################################################## + # prepare for test COPY_TESTFILES_TO_TESTDIR diff --git a/tools/test/h5repack/h5repacktst.c b/tools/test/h5repack/h5repacktst.c index f6166da..0ae570b 100644 --- a/tools/test/h5repack/h5repacktst.c +++ b/tools/test/h5repack/h5repacktst.c @@ -3728,7 +3728,7 @@ out: H5Pclose(fcpl); H5Fclose(fid); } H5E_END_TRY; - if(fd > 0) + if(fd >= 0) HDclose(fd); return -1; @@ -3797,7 +3797,7 @@ out: H5Pclose(fcpl); H5Fclose(fid); } H5E_END_TRY; - if(fd > 0) + if(fd >= 0) HDclose(fd); return -1; @@ -3838,7 +3838,7 @@ make_userblock_file(void) out: - if(fd > 0) + if(fd >= 0) HDclose(fd); return -1; @@ -4134,13 +4134,19 @@ int write_dset_in(hid_t loc_id, } /* create a type larger than TEST_BUFSIZE */ - if ((tid = H5Tarray_create2(H5T_NATIVE_DOUBLE, 1, tdims)) < 0) + if ((tid = H5Tarray_create2(H5T_NATIVE_DOUBLE, 1, tdims)) < 0) { + HDfree(dbuf); goto out; + } size = H5Tget_size(tid); - if ((sid = H5Screate_simple(1, sdims, NULL)) < 0) + if ((sid = H5Screate_simple(1, sdims, NULL)) < 0) { + HDfree(dbuf); goto out; - if ((did = H5Dcreate2(loc_id, "arrayd", tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + } + if ((did = H5Dcreate2(loc_id, "arrayd", tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + HDfree(dbuf); goto out; + } #if defined(WRITE_ARRAY) H5Dwrite(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, dbuf); #endif @@ -4149,7 +4155,7 @@ int write_dset_in(hid_t loc_id, H5Dclose(did); H5Tclose(tid); H5Sclose(sid); - HDfree( dbuf ); + HDfree(dbuf); } /*------------------------------------------------------------------------- diff --git a/tools/test/h5stat/h5stat_gentest.c b/tools/test/h5stat/h5stat_gentest.c index 2daf24b..ae11032 100644 --- a/tools/test/h5stat/h5stat_gentest.c +++ b/tools/test/h5stat/h5stat_gentest.c @@ -14,7 +14,7 @@ /* * Generate the binary hdf5 files for the h5stat tests. * Usage: just execute the program without any arguments will - * generate all the binary hdf5 files + * generate all the binary hdf5 files * * If you regenerate the test files (e.g., changing some code, * trying it on a new platform, ...), you need to verify the correctness @@ -24,25 +24,25 @@ #include "H5private.h" /* For gen_newgrat_file() */ -#define NEWGRAT_FILE "h5stat_newgrat.h5" -#define DATASET_NAME "DATASET_NAME" -#define GROUP_NAME "GROUP" -#define ATTR_NAME "ATTR" -#define NUM_GRPS 35000 -#define NUM_ATTRS 100 +#define NEWGRAT_FILE "h5stat_newgrat.h5" +#define DATASET_NAME "DATASET_NAME" +#define GROUP_NAME "GROUP" +#define ATTR_NAME "ATTR" +#define NUM_GRPS 35000 +#define NUM_ATTRS 100 /* Declarations for gen_idx_file() */ -#define IDX_FILE "h5stat_idx.h5" -#define DSET "dset" -#define DSET_FILTER "dset_filter" +#define IDX_FILE "h5stat_idx.h5" +#define DSET "dset" +#define DSET_FILTER "dset_filter" /* For gen_threshold_file() */ -#define THRESHOLD_FILE "h5stat_threshold.h5" -#define THRES_ATTR_NAME "attr" -#define THRES_ATTR_GRP_NAME "grp_attr" -#define THRES_DSET_NAME "dset" -#define THRES_NUM 10 -#define THRES_NUM_25 25 +#define THRESHOLD_FILE "h5stat_threshold.h5" +#define THRES_ATTR_NAME "attr" +#define THRES_ATTR_GRP_NAME "grp_attr" +#define THRES_DSET_NAME "dset" +#define THRES_NUM 10 +#define THRES_NUM_25 25 /* For gen_err_refcount() */ #define ERR_REFCOUNT_FILE "h5stat_err_refcount.h5" @@ -51,7 +51,7 @@ * Generate HDF5 file with latest format with * NUM_GRPS groups and NUM_ATTRS attributes for the dataset */ -static void +static void gen_newgrat_file(const char *fname) { hid_t fcpl = -1; /* File creation property */ @@ -62,79 +62,66 @@ gen_newgrat_file(const char *fname) hid_t sid = -1; /* Dataspace id */ hid_t attr_id = -1; /* Attribute id */ hid_t did = -1; /* Dataset id */ - char name[30]; /* Group name */ - char attrname[30]; /* Attribute name */ - int i; /* Local index variable */ + char name[30]; /* Group name */ + char attrname[30]; /* Attribute name */ + int i; /* Local index variable */ /* Get a copy file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - goto error; + goto error; /* Set to use latest library format */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - goto error; + goto error; /* Get a copy of file creation property list */ if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) - goto error; + goto error; /* Set file space handling strategy */ if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, 1, (hsize_t)1) < 0) - goto error; + goto error; /* Create file */ if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, fcpl, fapl)) < 0) - goto error; + goto error; /* Create NUM_GRPS groups in the root group */ for(i = 1; i <= NUM_GRPS; i++) { sprintf(name, "%s%d", GROUP_NAME,i); if((gid = H5Gcreate2(fid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Gclose(gid) < 0) - goto error; + goto error; } /* end for */ /* Create a datatype to commit and use */ if((tid = H5Tcopy(H5T_NATIVE_INT)) < 0) - goto error; + goto error; /* Create dataspace for dataset */ if((sid = H5Screate(H5S_SCALAR)) < 0) - goto error; + goto error; /* Create dataset */ if((did = H5Dcreate2(fid, DATASET_NAME, tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create NUM_ATTRS for the dataset */ for(i = 1; i <= NUM_ATTRS; i++) { sprintf(attrname, "%s%d", ATTR_NAME,i); if((attr_id = H5Acreate2(did, attrname, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Aclose(attr_id) < 0) - goto error; + goto error; } /* end for */ /* Close dataset, dataspace, datatype, file */ - if(H5Pclose(fapl) < 0) - goto error; - if(H5Pclose(fcpl) < 0) - goto error; - if(H5Dclose(did) < 0) - goto error; - if(H5Sclose(sid) < 0) - goto error; - if(H5Tclose(tid) < 0) - goto error; - if(H5Fclose(fid) < 0) - goto error; - error: H5E_BEGIN_TRY { - H5Pclose(fapl); - H5Pclose(fcpl); - H5Aclose(attr_id); + H5Pclose(fapl); + H5Pclose(fcpl); + H5Aclose(attr_id); H5Dclose(did); H5Tclose(tid); H5Sclose(sid); @@ -145,192 +132,175 @@ error: /* * Generate an HDF5 file with groups, datasets, attributes for testing the options: - * -l N (--links=N): Set the threshold for # of links when printing information for small groups. - * -m N (--dims=N): Set the threshold for the # of dimension sizes when printing information for small datasets. - * -a N (--numattrs=N): Set the threshold for the # of attributes when printing information for small # of attributes. + * -l N (--links=N): Set the threshold for # of links when printing information for small groups. + * -m N (--dims=N): Set the threshold for the # of dimension sizes when printing information for small datasets. + * -a N (--numattrs=N): Set the threshold for the # of attributes when printing information for small # of attributes. */ static void gen_threshold_file(const char *fname) { - hid_t fid; /* File ID */ - hid_t sid0, sid1, sid2, sid3, sid4; /* Dataspace IDs */ - hid_t did; /* Dataset ID */ - hid_t attr_id; /* Attribute ID */ - hid_t gid; /* Group ID */ - hsize_t two_dims[] = {2, 5}; /* Dimension array */ - hsize_t one_dims[] = {6}; /* Dimension array */ - hsize_t zero_dims[] = {0}; /* Dimension array */ - char name[30]; /* Name */ - unsigned i; /* Local index variable */ + hid_t fid = -1; /* File ID */ + hid_t sid0 = -1; /* Dataspace IDs */ + hid_t sid1 = -1; /* Dataspace IDs */ + hid_t sid2 = -1; /* Dataspace IDs */ + hid_t sid3 = -1; /* Dataspace IDs */ + hid_t sid4 = -1; /* Dataspace IDs */ + hid_t did = -1; /* Dataset ID */ + hid_t attr_id = -1; /* Attribute ID */ + hid_t gid = -1; /* Group ID */ + hsize_t two_dims[] = {2, 5}; /* Dimension array */ + hsize_t one_dims[] = {6}; /* Dimension array */ + hsize_t zero_dims[] = {0}; /* Dimension array */ + char name[30]; /* Name */ + unsigned i; /* Local index variable */ /* Create file */ if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create 1-D dataspace with zero dimension size */ if((sid0 = H5Screate_simple(1, zero_dims, NULL)) < 0) - goto error; + goto error; /* Create 1-D dataspace with non-zero dimension size*/ if((sid1 = H5Screate_simple(1, one_dims, NULL)) < 0) - goto error; + goto error; /* Create 2-D dataspace */ if((sid2 = H5Screate_simple(2, two_dims, NULL)) < 0) - goto error; + goto error; /* Create scalar dataspace */ if((sid3 = H5Screate(H5S_SCALAR)) < 0) - goto error; + goto error; /* Create null dataspace */ if((sid4 = H5Screate(H5S_NULL)) < 0) - goto error; + goto error; /* Create an attribute for the root group */ if((attr_id = H5Acreate2(fid, "attr", H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Aclose(attr_id) < 0) - goto error; + goto error; /* Create 1-D dataset with zero dimension size for the root group */ if((did = H5Dcreate2(fid, "zero_dset", H5T_NATIVE_UCHAR, sid0, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create 11 attributes for the dataset */ for(i = 1; i <= (THRES_NUM+1); i++) { sprintf(name, "%s%d", THRES_ATTR_NAME,i); if((attr_id = H5Acreate2(did, name, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Aclose(attr_id) < 0) - goto error; + goto error; } if(H5Dclose(did) < 0) - goto error; + goto error; /* Create dataset with scalar dataspace for the root group */ if((did = H5Dcreate2(fid, "scalar_dset", H5T_NATIVE_UCHAR, sid3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Dclose(did) < 0) - goto error; + goto error; /* Create dataset with null dataspace for the root group */ if((did = H5Dcreate2(fid, "null_dset", H5T_NATIVE_UCHAR, sid4, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Dclose(did) < 0) - goto error; + goto error; /* Create 2-D dataset for the root group */ if((did = H5Dcreate2(fid, "dset", H5T_NATIVE_UCHAR, sid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create 10 attributes for the 2-D dataset */ for(i = 1; i <= THRES_NUM; i++) { sprintf(name, "%s%d", THRES_ATTR_NAME,i); if((attr_id = H5Acreate2(did, name, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Aclose(attr_id) < 0) - goto error; + goto error; } if(H5Dclose(did) < 0) - goto error; + goto error; /* Create first group */ if((gid = H5Gcreate2(fid, "group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create an attribute for the group */ if((attr_id = H5Acreate2(gid, "ATTR", H5T_NATIVE_INT, sid3, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Close attribute */ if(H5Aclose(attr_id) < 0) - goto error; + goto error; /* Create 10 1-D datasets with non-zero dimension size for the group */ for(i = 1; i <= THRES_NUM; i++) { - /* set up dataset name */ + /* set up dataset name */ sprintf(name, "%s%d", THRES_DSET_NAME,i); - /* Create the dataset */ - if((did = H5Dcreate2(gid, name, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + /* Create the dataset */ + if((did = H5Dcreate2(gid, name, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; - /* Close the dataset */ + /* Close the dataset */ if(H5Dclose(did) < 0) - goto error; + goto error; } /* Close the group */ if(H5Gclose(gid) < 0) - goto error; + goto error; /* Create second group */ if((gid = H5Gcreate2(fid, "group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create 25 attributes for the group */ for(i = 1; i <= THRES_NUM_25; i++) { - /* Set up attribute name */ + /* Set up attribute name */ sprintf(name, "%s%d", THRES_ATTR_GRP_NAME,i); - /* Create the attribute */ + /* Create the attribute */ if((attr_id = H5Acreate2(gid, name, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; - /* Close the attribute */ + /* Close the attribute */ if(H5Aclose(attr_id) < 0) - goto error; + goto error; } /* Close the group */ if(H5Gclose(gid) < 0) - goto error; + goto error; /* Create third group */ if((gid = H5Gcreate2(fid, "group3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + goto error; /* Create 9 1-D datasets with non-zero dimension size for the group */ for(i = 1; i < THRES_NUM; i++) { - /* set up dataset name */ + /* set up dataset name */ sprintf(name, "%s%d", THRES_DSET_NAME,i); - /* Create the dataset */ - if((did = H5Dcreate2(gid, name, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + /* Create the dataset */ + if((did = H5Dcreate2(gid, name, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; - /* Close the dataset */ + /* Close the dataset */ if(H5Dclose(did) < 0) - goto error; + goto error; } - /* Close the group */ - if(H5Gclose(gid) < 0) - goto error; - - - /* Close dataspaces */ - if(H5Sclose(sid0) < 0) - goto error; - if(H5Sclose(sid1) < 0) - goto error; - if(H5Sclose(sid2) < 0) - goto error; - if(H5Sclose(sid3) < 0) - goto error; - if(H5Sclose(sid4) < 0) - goto error; - - /* Close file */ - if(H5Fclose(fid) < 0) - goto error; - error: H5E_BEGIN_TRY { H5Gclose(gid); - H5Aclose(attr_id); + H5Aclose(attr_id); H5Dclose(did); H5Sclose(sid0); H5Sclose(sid1); @@ -346,84 +316,73 @@ error: * Function: gen_idx_file * * Purpose: Create a file with datasets that use Fixed Array indexing: - * one dataset: fixed dimension, chunked layout, w/o filters - * one dataset: fixed dimension, chunked layout, w/ filters + * one dataset: fixed dimension, chunked layout, w/o filters + * one dataset: fixed dimension, chunked layout, w/ filters * */ -static void +static void gen_idx_file(const char *fname) { - hid_t fapl = -1; /* file access property id */ - hid_t fid = -1; /* file id */ - hid_t sid = -1; /* space id */ - hid_t dcpl = -1; /* dataset creation property id */ - hid_t did = -1, did2 = -1; /* dataset id */ - hsize_t dims[1] = {10}; /* dataset dimension */ - hsize_t c_dims[1] = {2}; /* chunk dimension */ - int i; /* local index variable */ - int buf[10]; /* data buffer */ + hid_t fapl = -1; /* file access property id */ + hid_t fid = -1; /* file id */ + hid_t sid = -1; /* space id */ + hid_t dcpl = -1; /* dataset creation property id */ + hid_t did = -1, did2 = -1; /* dataset id */ + hsize_t dims[1] = {10}; /* dataset dimension */ + hsize_t c_dims[1] = {2}; /* chunk dimension */ + int i; /* local index variable */ + int buf[10]; /* data buffer */ /* Get a copy of the file access property */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - goto error; + goto error; /* Set the "use the latest format" bounds for creating objects in the file */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - goto error; + goto error; /* Create file */ if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) - goto error; + goto error; /* Create data */ for(i = 0; i < 10; i++) - buf[i] = i; + buf[i] = i; /* Set chunk */ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - goto error; + goto error; if(H5Pset_chunk(dcpl, 1, c_dims) < 0) - goto error; + goto error; /* Create a 1D dataset */ if((sid = H5Screate_simple(1, dims, NULL)) < 0) - goto error; + goto error; if((did = H5Dcreate2(fid, DSET, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - goto error; - + goto error; + /* Write to the dataset */ if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + goto error; #if defined (H5_HAVE_FILTER_DEFLATE) /* set deflate data */ if(H5Pset_deflate(dcpl, 9) < 0) - goto error; + goto error; /* Create and write the dataset */ if((did2 = H5Dcreate2(fid, DSET_FILTER, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - goto error; + goto error; if(H5Dwrite(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + goto error; /* Close the dataset */ if(H5Dclose(did2) < 0) - goto error; + goto error; #endif /* closing: dataspace, dataset, file */ - if(H5Pclose(fapl) < 0) - goto error; - if(H5Pclose(dcpl) < 0) - goto error; - if(H5Sclose(sid) < 0) - goto error; - if(H5Dclose(did) < 0) - goto error; - if(H5Fclose(fid) < 0) - goto error; - error: H5E_BEGIN_TRY { H5Pclose(fapl); @@ -451,7 +410,7 @@ error: * H5O_refcount_decode in the jira issue. * */ -static void +static void gen_err_refcount(const char *fname) { hid_t fid = -1; /* File identifier */ @@ -525,16 +484,13 @@ gen_err_refcount(const char *fname) /* Offset of the message ID to modify is as follows: */ /* 4520: the offset of the object header containing the attribute message with the committed datatype */ - /* 24: the offset in the object header containing the version of the + /* 24: the offset in the object header containing the version of the attribute message */ - if((fd = HDopen(fname, O_RDWR, 0633)) < 0) - goto error; - if(HDlseek(fd, 4520+24, SEEK_SET) < 0) - goto error; - if(HDwrite(fd, &val, 2) < 0) - goto error; - if(HDclose(fd) < 0) - goto error; + if((fd = HDopen(fname, O_RDWR, 0633)) >= 0) { + HDlseek(fd, 4520+24, SEEK_SET); + HDwrite(fd, &val, 2); + HDclose(fd); + } error: H5E_BEGIN_TRY { @@ -548,8 +504,8 @@ error: } H5E_END_TRY; } /* gen_err_refcount() */ -/* - * The following two test files are generated with older versions +/* + * The following two test files are generated with older versions * of the library for HDFFV-10333. They are used for testing in * testh5stat.sh.in. * @@ -559,7 +515,7 @@ error: * Then a "0" is written to the "dimension" field in the layout * message to trigger the error. * This is to verify HDFFV-10333 that h5stat will exit gracefully - * when encountered error similar to H5O__layout_decode in the + * when encountered error similar to H5O__layout_decode in the * jira issue. * * (2) h5stat_err_old_fill.h5 @@ -568,7 +524,7 @@ error: * Then an illegal size is written to the "size" fild in the * fill value message to trigger the error. * This is to verify HDFFV-10333 that h5stat will exit gracefully - * when encountered error similar to H5O_fill_old_decode in the + * when encountered error similar to H5O_fill_old_decode in the * jira issue. */ diff --git a/tools/test/h5stat/testh5stat.sh.in b/tools/test/h5stat/testh5stat.sh.in index 5082daf..0a5127f 100644 --- a/tools/test/h5stat/testh5stat.sh.in +++ b/tools/test/h5stat/testh5stat.sh.in @@ -249,7 +249,6 @@ TOOLTEST h5stat_help2.ddl --help TOOLTEST h5stat_notexist.ddl notexist.h5 TOOLTEST h5stat_nofile.ddl '' - # Test file with groups, compressed datasets, user-applied fileters, etc. # h5stat_filters.h5 is a copy of ../../testfiles/tfilters.h5 as of release 1.8.0-alpha4 TOOLTEST h5stat_filters.ddl h5stat_filters.h5 diff --git a/tools/test/perform/zip_perf.c b/tools/test/perform/zip_perf.c index 0636d3b..e301bb3 100644 --- a/tools/test/perform/zip_perf.c +++ b/tools/test/perform/zip_perf.c @@ -419,7 +419,9 @@ fill_with_random_data(Bytef *src, uLongf src_len) buf += rc; len -= (size_t)rc; } - } else { + HDclose(fd); + } + else { HDfprintf(stdout, "Using random() for random data\n"); for (u = 0; u < src_len; ++u) @@ -557,7 +559,7 @@ main(int argc, char **argv) int opt; prog = argv[0]; - + /* Initialize h5tools lib */ h5tools_init(); -- cgit v0.12