From 4e6b652c3d0fdd94fc7f2aa588ab63cea7bcde64 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 8 Aug 2012 20:02:02 -0500 Subject: [svn-r22647] Description: Bring r22646 from trunk to 1.8 branch: Changes resulting from Klocwork static analysis tool, from Mark Miller @ LLNL (miller86@llnl.gov). Tested on: Mac OS X/64 10.7.4 (amazon) w/debug, C++ & FORTRAN, using gcc 4.7.x (too minor to require h5committest) --- hl/test/test_image.c | 7 ++++-- src/H5Dchunk.c | 4 +++- src/H5Doh.c | 2 +- src/H5Eint.c | 10 ++++++-- src/H5FDcore.c | 10 ++++---- src/H5FDmpi.c | 19 ++++++++++----- src/H5HFsection.c | 12 ++++++++-- src/H5HG.c | 2 +- src/H5MF.c | 4 ++++ src/H5Ocopy.c | 5 +++- src/H5Otest.c | 2 +- src/H5Pfapl.c | 47 ++++++++++++++++++++------------------ src/H5Shyper.c | 2 +- src/H5Spoint.c | 2 +- src/H5Sselect.c | 2 +- src/H5Tarray.c | 3 ++- src/H5trace.c | 1 + test/accum.c | 18 ++++++++------- test/cache_common.c | 2 +- test/dsets.c | 14 +++++------- test/dt_arith.c | 6 ++--- test/dtypes.c | 35 +++++++++++++++------------- test/file_image.c | 26 ++++++++++++--------- test/freespace.c | 2 ++ test/h5test.c | 4 ++++ test/ntypes.c | 1 + test/objcopy.c | 2 +- test/tunicode.c | 2 ++ tools/h5repack/h5repack_copy.c | 2 +- tools/h5repack/h5repack_opttable.c | 2 +- tools/misc/talign.c | 15 +++++++----- 31 files changed, 162 insertions(+), 103 deletions(-) diff --git a/hl/test/test_image.c b/hl/test/test_image.c index 2e1e465..bd4a947 100644 --- a/hl/test/test_image.c +++ b/hl/test/test_image.c @@ -514,6 +514,7 @@ static int test_generate(void) char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing data file */ int i; + int retval = FAIL; /* create a file using default properties */ if ((fid=H5Fcreate(FILE3,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) @@ -686,15 +687,17 @@ static int test_generate(void) if (H5Fclose(fid)<0) goto out; - return 0; + /* Indicate success */ + retval = 0; /* error zone, gracefully close */ out: + HDfree(data); H5E_BEGIN_TRY { H5Fclose(fid); } H5E_END_TRY; H5_FAILED(); - return FAIL; + return retval; } diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 328f06a..2d08f67 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -3798,7 +3798,9 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) /* * Determine the chunks which need to be filled or removed */ - for(op_dim=0; op_dimlib_vers) eprint->cls.lib_vers = cls_ptr->lib_vers; - fprintf(stream, "%s-DIAG: Error detected in %s (%s) ", cls_ptr->cls_name, cls_ptr->lib_name, cls_ptr->lib_vers); + fprintf(stream, "%s-DIAG: Error detected in %s (%s) ", + (cls_ptr->cls_name ? cls_ptr->cls_name : "(null)"), + (cls_ptr->lib_name ? cls_ptr->lib_name : "(null)"), + (cls_ptr->lib_vers ? cls_ptr->lib_vers : "(null)")); /* try show the process or thread id in multiple processes cases*/ #ifdef H5_HAVE_PARALLEL @@ -387,7 +390,10 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data) if(cls_ptr->lib_vers) eprint->cls.lib_vers = cls_ptr->lib_vers; - fprintf(stream, "%s-DIAG: Error detected in %s (%s) ", cls_ptr->cls_name, cls_ptr->lib_name, cls_ptr->lib_vers); + fprintf(stream, "%s-DIAG: Error detected in %s (%s) ", + (cls_ptr->cls_name ? cls_ptr->cls_name : "(null)"), + (cls_ptr->lib_name ? cls_ptr->lib_name : "(null)"), + (cls_ptr->lib_vers ? cls_ptr->lib_vers : "(null)")); /* try show the process or thread id in multiple processes cases*/ #ifdef H5_HAVE_PARALLEL diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 6f9a41a..94ddc4d 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -425,8 +425,9 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "maxaddr overflow") HDassert(H5P_DEFAULT != fapl_id); if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") - fa = (H5FD_core_fapl_t *)H5P_get_driver_info(plist); + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") + if(NULL == (fa = (H5FD_core_fapl_t *)H5P_get_driver_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info") /* Build the open flags */ o_flags = (H5F_ACC_RDWR & flags) ? O_RDWR : O_RDONLY; @@ -441,6 +442,7 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, /* If the file image exists and this is an open, make sure the file doesn't exist */ HDassert(((file_image_info.buffer != NULL) && (file_image_info.size > 0)) || ((file_image_info.buffer == NULL) && (file_image_info.size == 0))); + HDmemset(&sb, 0, sizeof(sb)); if((file_image_info.buffer != NULL) && !(H5F_ACC_CREAT & flags)) { if(HDopen(name, o_flags, 0666) >= 0) HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, NULL, "file already exists") @@ -460,7 +462,7 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, * store is off is when the backing_store flag is off and H5F_ACC_CREAT is * on. */ else if(fa->backing_store || !(H5F_ACC_CREAT & flags)) { - if(fa && (fd = HDopen(name, o_flags, 0666)) < 0) + if((fd = HDopen(name, o_flags, 0666)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") if(HDfstat(fd, &sb) < 0) HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") @@ -477,7 +479,7 @@ H5FD_core_open(const char *name, unsigned flags, hid_t fapl_id, * default value. But if the file access property list was zero then use * the default value instead. */ - file->increment = (fa && fa->increment>0) ? fa->increment : H5FD_CORE_INCREMENT; + file->increment = (fa->increment>0) ? fa->increment : H5FD_CORE_INCREMENT; /* If save data in backing store. */ file->backing_store = fa->backing_store; diff --git a/src/H5FDmpi.c b/src/H5FDmpi.c index 01c28e6..866a2cf 100644 --- a/src/H5FDmpi.c +++ b/src/H5FDmpi.c @@ -56,12 +56,15 @@ char H5FD_mpi_native_g[] = "native"; int H5FD_mpi_get_rank(const H5FD_t *file) { - const H5FD_class_mpi_t *cls=(const H5FD_class_mpi_t *)(file->cls); + const H5FD_class_mpi_t *cls; + int ret_value; FUNC_ENTER_NOAPI(FAIL) - assert(file && cls); + assert(file); + cls = (const H5FD_class_mpi_t *)(file->cls); + assert(cls); assert(cls->get_rank); /* All MPI drivers must implement this */ /* Dispatch to driver */ @@ -92,12 +95,14 @@ done: int H5FD_mpi_get_size(const H5FD_t *file) { - const H5FD_class_mpi_t *cls=(const H5FD_class_mpi_t *)(file->cls); + const H5FD_class_mpi_t *cls; int ret_value; FUNC_ENTER_NOAPI(FAIL) - assert(file && cls); + assert(file); + cls = (const H5FD_class_mpi_t *)(file->cls); + assert(cls); assert(cls->get_size); /* All MPI drivers must implement this */ /* Dispatch to driver */ @@ -128,12 +133,14 @@ done: MPI_Comm H5FD_mpi_get_comm(const H5FD_t *file) { - const H5FD_class_mpi_t *cls=(const H5FD_class_mpi_t *)(file->cls); + const H5FD_class_mpi_t *cls; MPI_Comm ret_value; FUNC_ENTER_NOAPI(MPI_COMM_NULL) - assert(file && cls); + assert(file); + cls = (const H5FD_class_mpi_t *)(file->cls); + assert(cls); assert(cls->get_comm); /* All MPI drivers must implement this */ /* Dispatch to driver */ diff --git a/src/H5HFsection.c b/src/H5HFsection.c index e9ea7e0..72ea100 100644 --- a/src/H5HFsection.c +++ b/src/H5HFsection.c @@ -2398,7 +2398,10 @@ H5HF_sect_indirect_init_rows(H5HF_hdr_t *hdr, hid_t dxpl_id, HDassert(sect->u.indirect.span_size > 0); /* Reset reference count for indirect section */ + /* (Also reset the direct & indirect row pointers */ sect->u.indirect.rc = 0; + sect->u.indirect.dir_rows = NULL; + sect->u.indirect.indir_ents = NULL; /* Set up direct block information, if necessary */ if(start_row < hdr->man_dtable.max_direct_rows) { @@ -2424,7 +2427,6 @@ H5HF_sect_indirect_init_rows(H5HF_hdr_t *hdr, hid_t dxpl_id, /* No rows of direct blocks covered, reset direct row information */ dir_nrows = 0; sect->u.indirect.dir_nrows = 0; - sect->u.indirect.dir_rows = NULL; } /* end else */ /* Set up indirect block information, if necessary */ @@ -2459,7 +2461,6 @@ H5HF_sect_indirect_init_rows(H5HF_hdr_t *hdr, hid_t dxpl_id, else { /* No indirect block entries covered, reset indirect row information */ sect->u.indirect.indir_nents = 0; - sect->u.indirect.indir_ents = NULL; } /* end else */ /* Set up initial row information */ @@ -2598,6 +2599,13 @@ H5HF_sect_indirect_init_rows(H5HF_hdr_t *hdr, hid_t dxpl_id, (sect->u.indirect.indir_nents + sect->u.indirect.dir_nrows)); done: + if(ret_value < 0) { + if(sect->u.indirect.indir_ents) + H5MM_xfree(sect->u.indirect.indir_ents); + if(sect->u.indirect.dir_rows) + H5MM_xfree(sect->u.indirect.dir_rows); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5HF_sect_indirect_init_rows() */ diff --git a/src/H5HG.c b/src/H5HG.c index 7c2b282..3bf2b8f 100644 --- a/src/H5HG.c +++ b/src/H5HG.c @@ -136,7 +136,7 @@ H5HG_create(H5F_t *f, hid_t dxpl_id, size_t size) { H5HG_heap_t *heap = NULL; uint8_t *p = NULL; - haddr_t addr; + haddr_t addr = HADDR_UNDEF; size_t n; haddr_t ret_value = HADDR_UNDEF; /* Return value */ diff --git a/src/H5MF.c b/src/H5MF.c index 3c14027..e154889 100644 --- a/src/H5MF.c +++ b/src/H5MF.c @@ -238,6 +238,7 @@ H5MF_alloc_open(H5F_t *f, hid_t dxpl_id, H5FD_mem_t type) */ HDassert(f); HDassert(f->shared); + HDassert(type != H5FD_MEM_NOLIST); HDassert(H5F_addr_defined(f->shared->fs_addr[type])); HDassert(f->shared->fs_state[type] == H5F_FS_STATE_CLOSED); @@ -285,6 +286,7 @@ H5MF_alloc_create(H5F_t *f, hid_t dxpl_id, H5FD_mem_t type) */ HDassert(f); HDassert(f->shared); + HDassert(type != H5FD_MEM_NOLIST); HDassert(!H5F_addr_defined(f->shared->fs_addr[type])); HDassert(f->shared->fs_state[type] == H5F_FS_STATE_CLOSED); @@ -335,6 +337,7 @@ H5MF_alloc_start(H5F_t *f, hid_t dxpl_id, H5FD_mem_t type) */ HDassert(f); HDassert(f->shared); + HDassert(type != H5FD_MEM_NOLIST); /* Check if the free space manager exists already */ if(H5F_addr_defined(f->shared->fs_addr[type])) { @@ -377,6 +380,7 @@ H5MF_alloc_close(H5F_t *f, hid_t dxpl_id, H5FD_mem_t type) */ HDassert(f); HDassert(f->shared); + HDassert(type != H5FD_MEM_NOLIST); HDassert(f->shared->fs_man[type]); HDassert(f->shared->fs_state[type] != H5F_FS_STATE_CLOSED); diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index 8df062b..bc71948 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -1056,11 +1056,15 @@ H5O_copy_header(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, FUNC_ENTER_NOAPI_NOINIT + /* Sanity check */ HDassert(oloc_src); HDassert(oloc_src->file); HDassert(H5F_addr_defined(oloc_src->addr)); HDassert(oloc_dst->file); + /* Intialize copy info before errors can be thrown */ + HDmemset(&cpy_info, 0, sizeof(H5O_copy_t)); + /* Get the copy property list */ if(NULL == (ocpy_plist = (H5P_genplist_t *)H5I_object(ocpypl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list") @@ -1078,7 +1082,6 @@ H5O_copy_header(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get callback info") /* Convert copy flags into copy struct */ - HDmemset(&cpy_info, 0, sizeof(H5O_copy_t)); if((cpy_option & H5O_COPY_SHALLOW_HIERARCHY_FLAG) > 0) { cpy_info.copy_shallow = TRUE; cpy_info.max_depth = 1; diff --git a/src/H5Otest.c b/src/H5Otest.c index 898326c..0b33e49 100644 --- a/src/H5Otest.c +++ b/src/H5Otest.c @@ -498,7 +498,7 @@ H5O_expunge_chunks_test(const H5O_loc_t *loc, hid_t dxpl_id) /* Safety check */ nchunks = oh->nchunks; - HDassert(nchunks < NELMTS(chk_addr)); + HDassert(0 < nchunks && nchunks < NELMTS(chk_addr)); /* Iterate over all the chunks, saving the chunk addresses */ for(u = 0; u < oh->nchunks; u++) diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index f2af61b..9b5d1b0 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -2494,12 +2494,13 @@ done: herr_t H5P_file_image_info_copy(const char UNUSED *name, size_t UNUSED size, void *value) { - H5FD_file_image_info_t *info; /* Image info struct */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT if(value) { + H5FD_file_image_info_t *info; /* Image info struct */ + info = (H5FD_file_image_info_t *)value; /* verify file image field consistancy */ @@ -2533,16 +2534,17 @@ H5P_file_image_info_copy(const char UNUSED *name, size_t UNUSED size, void *valu else HDmemcpy(info->buffer, old_buffer, info->size); } /* end if */ - } /* end if */ - /* Copy udata if it exists */ - if(info->callbacks.udata) { - void *old_udata = info->callbacks.udata; + /* Copy udata if it exists */ + if(info->callbacks.udata) { + void *old_udata = info->callbacks.udata; + + if(NULL == info->callbacks.udata_copy) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "udata_copy not defined") - if(NULL == info->callbacks.udata_copy) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "udata_copy not defined") + info->callbacks.udata = info->callbacks.udata_copy(old_udata); + } /* end if */ - info->callbacks.udata = info->callbacks.udata_copy(old_udata); } /* end if */ done: @@ -2567,32 +2569,33 @@ done: herr_t H5P_file_image_info_close(const char UNUSED *name, size_t UNUSED size, void *value) { - H5FD_file_image_info_t info; /* Image info struct */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT if(value) { - info = *(H5FD_file_image_info_t *)value; + H5FD_file_image_info_t *info; /* Image info struct */ + + info = (H5FD_file_image_info_t *)value; - if(info.buffer != NULL && info.size > 0) { + if(info->buffer != NULL && info->size > 0) { /* Free buffer */ - if(info.callbacks.image_free) { - if(info.callbacks.image_free(info.buffer, H5FD_FILE_IMAGE_OP_PROPERTY_LIST_CLOSE, - info.callbacks.udata) < 0) + if(info->callbacks.image_free) { + if(info->callbacks.image_free(info->buffer, H5FD_FILE_IMAGE_OP_PROPERTY_LIST_CLOSE, + info->callbacks.udata) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "image_free callback failed") } /* end if */ else - H5MM_xfree(info.buffer); + H5MM_xfree(info->buffer); } /* end if */ - } /* end if */ - /* Free udata if it exists */ - if(info.callbacks.udata) { - if(NULL == info.callbacks.udata_free) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "udata_free not defined") - if(info.callbacks.udata_free(info.callbacks.udata) < 0) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "udata_free callback failed") + /* Free udata if it exists */ + if(info->callbacks.udata) { + if(NULL == info->callbacks.udata_free) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "udata_free not defined") + if(info->callbacks.udata_free(info->callbacks.udata) < 0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "udata_free callback failed") + } /* end if */ } /* end if */ done: diff --git a/src/H5Shyper.c b/src/H5Shyper.c index d9b306d..d88ac35 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -2784,7 +2784,7 @@ H5S_hyper_offset(const H5S_t *space, hsize_t *offset) FUNC_ENTER_NOAPI(FAIL) - HDassert(space); + HDassert(space && space->extent.rank>0); HDassert(offset); /* Start at linear offset 0 */ diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 817b2f2..b758a92 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -643,7 +643,7 @@ H5S_point_copy(H5S_t *dst, const H5S_t *src, hbool_t UNUSED share_selection) } /* end while */ done: - if(ret_value < 0) { + if(ret_value < 0 && dst->select.sel_info.pnt_lst) { /* Traverse the (incomplete?) dst list, freeing all memory */ curr = dst->select.sel_info.pnt_lst->head; while(curr) { diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 91aed1e..9a993a5 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -67,7 +67,7 @@ H5S_select_offset(H5S_t *space, const hssize_t *offset) /* Check args */ HDassert(space); - HDassert(space->extent.rank); + HDassert(0 < space->extent.rank && space->extent.rank <= H5S_MAX_RANK); HDassert(offset); /* Copy the offset over */ diff --git a/src/H5Tarray.c b/src/H5Tarray.c index 9986631..c73b934 100644 --- a/src/H5Tarray.c +++ b/src/H5Tarray.c @@ -194,7 +194,8 @@ H5T__array_create(H5T_t *base, unsigned ndims, const hsize_t dim[/* ndims */]) ret_value->shared->type = H5T_ARRAY; /* Copy the base type of the array */ - ret_value->shared->parent = H5T_copy(base, H5T_COPY_ALL); + if(NULL == (ret_value->shared->parent = H5T_copy(base, H5T_COPY_ALL))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "unable to copy base datatype") /* Set the array parameters */ ret_value->shared->u.array.ndims = ndims; diff --git a/src/H5trace.c b/src/H5trace.c index ec2ac33..e0b5794 100644 --- a/src/H5trace.c +++ b/src/H5trace.c @@ -212,6 +212,7 @@ H5_trace(const double *returning, const char *func, const char *type, ...) if('[' == *type) { if('a' == type[1]) { asize_idx = (int)HDstrtol(type + 2, &rest, 10); + HDassert(0 <= asize_idx && asize_idx < (int) NELMTS(asize)); HDassert(']'==*rest); type = rest + 1; } else { diff --git a/test/accum.c b/test/accum.c index c5f6610..e4c1bd8 100644 --- a/test/accum.c +++ b/test/accum.c @@ -1793,15 +1793,17 @@ accum_printf(void) printf("=====================================================\n"); } else { printf("=====================================================\n"); - printf(" accumulator allocated size == %lu\n", (unsigned long)accum->alloc_size); - printf(" accumulated data size == %lu\n", (unsigned long)accum->size); - printf(" accumulator dirty? == %d\n", accum->dirty); + printf(" accumulator allocated size == %zu\n", accum->alloc_size); + printf(" accumulated data size == %zu\n", accum->size); + HDfprintf(stdout, " accumulator dirty? == %t\n", accum->dirty); printf("=====================================================\n"); - printf(" start of accumulated data, loc = %llu\n", accum->loc); - if (accum->dirty) printf(" start of dirty region, loc = %llu\n", accum->loc + accum->dirty_off); - if (accum->dirty) printf(" end of dirty region, loc = %llu\n", accum->loc + accum->dirty_off + accum->dirty_len); - printf(" end of accumulated data, loc = %llu\n", accum->loc + accum->size); - printf(" end of accumulator allocation, loc = %llu\n", accum->loc + accum->alloc_size); + HDfprintf(stdout, " start of accumulated data, loc = %a\n", accum->loc); + if(accum->dirty) { + HDfprintf(stdout, " start of dirty region, loc = %a\n", (haddr_t)(accum->loc + accum->dirty_off)); + HDfprintf(stdout, " end of dirty region, loc = %a\n", (haddr_t)(accum->loc + accum->dirty_off + accum->dirty_len)); + } /* end if */ + HDfprintf(stdout, " end of accumulated data, loc = %a\n", (haddr_t)(accum->loc + accum->size)); + HDfprintf(stdout, " end of accumulator allocation, loc = %a\n", (haddr_t)(accum->loc + accum->alloc_size)); printf("=====================================================\n"); } printf("\n\n"); diff --git a/test/cache_common.c b/test/cache_common.c index c2c0b12..f41e6af 100644 --- a/test/cache_common.c +++ b/test/cache_common.c @@ -1879,7 +1879,7 @@ verify_entry_status(H5C_t * cache_ptr, int num_entries, struct expected_entry_status expected[]) { - static char msg[128]; + static char msg[256]; hbool_t in_cache = FALSE; /* will set to TRUE if necessary */ int i; test_entry_t * entry_ptr; diff --git a/test/dsets.c b/test/dsets.c index 043c44a..3b0d25d 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -1004,8 +1004,8 @@ test_conv_buffer(hid_t fid) herr_t status = -1; int j, k, l; - CmpField *cf; - CmpFieldR *cfrR; + CmpField *cf = NULL; + CmpFieldR *cfrR = NULL; hid_t dataset = -1; /* dataset ID */ hid_t space = -1; /* data space ID */ @@ -1019,7 +1019,7 @@ test_conv_buffer(hid_t fid) TESTING("data type conversion buffer size"); - cf = (CmpField *)HDcalloc((size_t)1, sizeof(CmpField)); + if ((cf = (CmpField *)HDcalloc((size_t)1, sizeof(CmpField))) == 0) goto error; /* Populate the data members */ for(j = 0; j < DIM1; j++) @@ -1068,7 +1068,7 @@ test_conv_buffer(hid_t fid) if(H5Tinsert(ctype2, "C", HOFFSET(CmpFieldR, c), arr_type5) < 0) goto error; /* Read should succeed since library will set conversion buffer big enough */ - cfrR = (CmpFieldR *)HDcalloc((size_t)1, sizeof(CmpFieldR)); + if ((cfrR = (CmpFieldR *)HDcalloc((size_t)1, sizeof(CmpFieldR))) == 0) goto error; if(H5Dread(dataset, ctype2, H5S_ALL, H5S_ALL, H5P_DEFAULT, cfrR) < 0) goto error; /* Read should fail since conversion buffer isn't big enough */ @@ -1105,10 +1105,8 @@ test_conv_buffer(hid_t fid) if(H5Tclose(arr_type5) < 0) goto error; if(H5Dclose(dataset) < 0) goto error; - if(cf) - HDfree(cf); - if(cfrR) - HDfree(cfrR); + HDfree(cf); + HDfree(cfrR); puts(" PASSED"); return(0); diff --git a/test/dt_arith.c b/test/dt_arith.c index 1b0af7a..e85e355 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -1105,9 +1105,9 @@ test_derived_flt(void) } fails_this_test = 0; - if(buf) free(buf); - if(saved_buf) free(saved_buf); - if(aligned) free(aligned); + free(buf); + free(saved_buf); + free(aligned); buf = NULL; saved_buf = NULL; aligned = NULL; diff --git a/test/dtypes.c b/test/dtypes.c index 17349b9..dca7eec 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -1127,10 +1127,8 @@ test_compound_5(void) } /* Free memory buffers */ - if(buf) - HDfree(buf); - if(bkg) - HDfree(bkg); + HDfree(buf); + HDfree(bkg); return retval; } @@ -4699,11 +4697,12 @@ test_bitfield_funcs(void) { hid_t type=-1, ntype=-1, super=-1; int size; - char* tag; + char* tag=0; H5T_pad_t inpad; H5T_cset_t cset; H5T_str_t strpad; herr_t ret; + int retval=-1; TESTING("some type functions for bitfield"); @@ -4787,16 +4786,18 @@ test_bitfield_funcs(void) goto error; } /* end if */ - H5Tclose(type); - H5Tclose(ntype); - PASSED(); - reset_hdf5(); - return 0; + retval = 0; error: + + if (retval == -1) retval = 1; + + HDfree(tag); + H5Tclose(ntype); H5Tclose(type); + if (retval == 0) PASSED(); reset_hdf5(); - return 1; + return retval; } @@ -7050,11 +7051,13 @@ error: */ int test_utf_ascii_conv(void) { - hid_t fid; - hid_t did; - hid_t utf8_vtid, ascii_vtid; - hid_t utf8_tid, ascii_tid; - hid_t sid; + hid_t fid = -1; + hid_t did = -1; + hid_t utf8_vtid = -1; + hid_t ascii_vtid = -1; + hid_t utf8_tid = -1; + hid_t ascii_tid = -1; + hid_t sid = -1; const char *utf8_w = "foo!"; char *ascii_r = NULL; const char *ascii_w = "bar!"; diff --git a/test/file_image.c b/test/file_image.c index 73c901e..9d7a48c 100644 --- a/test/file_image.c +++ b/test/file_image.c @@ -86,15 +86,16 @@ typedef struct { static int test_properties(void) { - hid_t fapl_1; - hid_t fapl_2; - char *buffer; + hid_t fapl_1 = -1; + hid_t fapl_2 = -1; + char *buffer = 0; int count = 10; - void *temp; - char *temp2; + void *temp = 0; + char *temp2 = 0; int i; size_t size; size_t temp_size; + int retval = 1; TESTING("File image property list functions"); @@ -145,18 +146,21 @@ test_properties(void) VERIFY(temp2 != temp, "Retrieved buffer is the same as previously retrieved buffer"); VERIFY(0 == HDmemcmp(temp2, buffer, size),"Buffers contain different data"); + retval = 0; + +error: + /* Close everything */ - if(H5Pclose(fapl_1) < 0) FAIL_STACK_ERROR - if(H5Pclose(fapl_2) < 0) FAIL_STACK_ERROR + if(H5Pclose(fapl_1) < 0) retval = 1; + if(H5Pclose(fapl_2) < 0) retval = 1; HDfree(buffer); HDfree(temp); HDfree(temp2); - PASSED(); - return 0; + if(retval == 0) + PASSED(); -error: - return 1; + return retval; } /* end test_properties() */ /****************************************************************************** diff --git a/test/freespace.c b/test/freespace.c index 6960e6d..c0df4c8 100644 --- a/test/freespace.c +++ b/test/freespace.c @@ -1522,8 +1522,10 @@ test_fs_sect_merge(hid_t fapl) /* Free the section node(s) */ if(TEST_sect_free((H5FS_section_info_t *)sect_node1) < 0) TEST_ERROR + sect_node1 = NULL; if(TEST_sect_free((H5FS_section_info_t *)sect_node2) < 0) TEST_ERROR + sect_node2 = NULL; /* Close the free space manager */ if(H5FS_close(f, H5P_DATASET_XFER_DEFAULT, frsp) < 0) diff --git a/test/h5test.c b/test/h5test.c index 7faba81..ea30fad 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -735,6 +735,8 @@ h5_set_info_object(void) valp = envp = next = HDstrdup(envp); + if (!valp) return 0; + /* create an INFO object if not created yet */ if (h5_io_info_g == MPI_INFO_NULL) MPI_Info_create(&h5_io_info_g); @@ -761,6 +763,8 @@ h5_set_info_object(void) while (*namep && (*namep == ' ' || *namep == '\t')) namep++; + if (!*namep) continue; /* was all white space, so move to next k/v pair */ + /* eat up any ending white spaces */ endp = &namep[strlen(namep) - 1]; diff --git a/test/ntypes.c b/test/ntypes.c index a63cea5..25060ec 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -1776,6 +1776,7 @@ test_vl_dtype(hid_t file) } /* end for */ HDfree(tmp); + tmp = NULL; } /* end for */ } /* end for */ diff --git a/test/objcopy.c b/test/objcopy.c index 1306524..01f93ed 100644 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -10351,7 +10351,7 @@ test_copy_cdt_merge_all_suggs(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fapl, hid_t did = -1; /* Dataset ID */ hid_t exp_did = -1; /* Dataset ID */ hid_t tid_short = -1; /* Datatype ID */ - hid_t exp_tid; /* Expected datatype ID */ + hid_t exp_tid = -1; /* Expected datatype ID */ hid_t ocpypl_id = -1; /* Object copy plist ID */ unsigned int i; /* Local index variables */ hsize_t dim1d[1]; /* Dataset dimensions */ diff --git a/test/tunicode.c b/test/tunicode.c index 892e563..bd3090c 100644 --- a/test/tunicode.c +++ b/test/tunicode.c @@ -161,6 +161,7 @@ void test_strpad(hid_t UNUSED fid, const char *string) /* Create a src_type that holds the UTF-8 string and its final NULL */ big_len = length + 1; /* +1 byte for final NULL */ + HDassert((2*big_len)<=sizeof(cmpbuf)); src_type = mkstr(big_len, H5T_STR_NULLTERM); CHECK(src_type, FAIL, "mkstr"); /* Create a dst_type that holds half of the UTF-8 string and a final @@ -224,6 +225,7 @@ void test_strpad(hid_t UNUSED fid, const char *string) /* Create a src_type that holds the UTF-8 string */ big_len = length; + HDassert((2*big_len)<=sizeof(cmpbuf)); src_type = mkstr(big_len, H5T_STR_NULLPAD); CHECK(src_type, FAIL, "mkstr"); /* Create a dst_type that holds half of the UTF-8 string */ diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index c936155..94bd565 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -1500,7 +1500,7 @@ static void print_dataset_info(hid_t dcpl_id, printf(FORMAT_OBJ,"dset",objname ); else { - char str[255], temp[20]; + char str[255], temp[28]; HDstrcpy(str,"dset "); HDstrcat(str,strfilter); sprintf(temp," (%.3f:1)",ratio); diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index 4ec7fcf..00e4bea 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -388,7 +388,7 @@ pack_info_t* options_get_object( const char *path, pack_opttbl_t *table ) { unsigned int i; - const char tbl_path[MAX_NC_NAME]; + const char tbl_path[MAX_NC_NAME+1]; /* +1 for start with "/" case */ for ( i = 0; i < table->nelems; i++) diff --git a/tools/misc/talign.c b/tools/misc/talign.c index 88ebaa6..b77d846 100644 --- a/tools/misc/talign.c +++ b/tools/misc/talign.c @@ -148,28 +148,31 @@ out: result = 1; mname = H5Tget_member_name(fix, 0); printf("%14s (%2d) %6s = %s\n", - mname, (int)H5Tget_member_offset(fix,0), + mname ? mname : "(null)", (int)H5Tget_member_offset(fix,0), string5, (char *)(data + H5Tget_member_offset(fix, 0))); - free(mname); + if(mname) + free(mname); fptr = (float *)(data + H5Tget_member_offset(fix, 1)); mname = H5Tget_member_name(fix, 1); printf("Data comparison:\n" "%14s (%2d) %6f = %f\n" " %6f = %f\n", - mname, (int)H5Tget_member_offset(fix,1), + mname ? mname : "(null)", (int)H5Tget_member_offset(fix,1), fok[0], fptr[0], fok[1], fptr[1]); - free(mname); + if(mname) + free(mname); fptr = (float *)(data + H5Tget_member_offset(fix, 2)); mname = H5Tget_member_name(fix, 2); printf("%14s (%2d) %6f = %f\n" " %6f = %6f\n", - mname, (int)H5Tget_member_offset(fix,2), + mname ? mname : "(null)", (int)H5Tget_member_offset(fix,2), fnok[0], fptr[0], fnok[1], fptr[1]); - free(mname); + if(mname) + free(mname); fptr = (float *)(data + H5Tget_member_offset(fix, 1)); printf("\n" -- cgit v0.12