From b9d042d2d273cacff8ecfeecd5e1bd75a6da7f3b Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 1 Nov 2012 11:01:37 -0500 Subject: [svn-r22998] Description: Clean up warnings and bring changes from Coverity branch back to trunk: r20451: Fixed coverity 810 r20454: Purpose: Fix coverity issue 816 Description: Modified various file drivers to always check the return value from H5P_get_driver_info. r20455: Purpose: Cleanup fix for coverity issue 816 Description: Removed redundant check for "fa" in H5FD_core_open. Tested on: Mac OSX/64 10.8.2 (amazon) w/debug (Too minor to require h5committest) --- src/H5FDcore.c | 2 +- src/H5FDdirect.c | 9 +++++---- src/H5FDfamily.c | 4 ++-- src/H5FDlog.c | 18 ++++++++--------- src/H5FDmpio.c | 4 ++-- src/H5FDmpiposix.c | 4 ++-- tools/lib/h5tools_dump.c | 50 ++++++++++++++++++++++++++++-------------------- tools/lib/h5tools_dump.h | 3 +-- 8 files changed, 51 insertions(+), 43 deletions(-) diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 932e2af..07f4551 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -481,7 +481,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->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/H5FDdirect.c b/src/H5FDdirect.c index 4721a44..9715bc1 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -533,7 +533,8 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd /* Get the driver specific information */ if(NULL == (plist = H5P_object_verify(fapl_id,H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") - fa = H5P_get_driver_info(plist); + if(NULL == (fa = (H5FD_direct_fapl_t *)H5P_get_driver_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") file->fd = fd; H5_ASSIGN_OVERFLOW(file->eof,sb.st_size,h5_stat_size_t,haddr_t); @@ -562,9 +563,9 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd * is to handle correctly the case that the file is in a different file system * than the one where the program is running. */ - buf1 = (int*)HDmalloc(sizeof(int)); - if (HDposix_memalign(&buf2, file->fa.mboundary, file->fa.fbsize) != 0) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "HDposix_memalign failed") + buf1 = (int *)HDmalloc(sizeof(int)); + if(HDposix_memalign(&buf2, file->fa.mboundary, file->fa.fbsize) != 0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "HDposix_memalign failed") if(o_flags & O_CREAT) { if(write(file->fd, (void*)buf1, sizeof(int))<0) { diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index f051269..dc535a2 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -675,8 +675,8 @@ H5FD_family_open(const char *name, unsigned flags, hid_t 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_family_fapl_t *)H5P_get_driver_info(plist); - HDassert(fa); + if(NULL == (fa = (H5FD_family_fapl_t *)H5P_get_driver_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") /* Check for new family file size. It's used by h5repart only. */ if(H5P_exist_plist(plist, H5F_ACS_FAMILY_NEWSIZE_NAME) > 0) { diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 6a2425c..9f4abd3 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -529,8 +529,8 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) /* Get the driver specific information */ if(NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list") - fa = (H5FD_log_fapl_t *)H5P_get_driver_info(plist); - HDassert(fa); + if(NULL == (fa = (H5FD_log_fapl_t *)H5P_get_driver_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") #ifdef H5_HAVE_GETTIMEOFDAY if(fa->flags & H5FD_LOG_TIME_OPEN) @@ -644,9 +644,9 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) #ifdef H5_HAVE_GETTIMEOFDAY if(file->fa.flags & H5FD_LOG_TIME_OPEN) - HDfprintf(file->logfp, "Open took: (%f s)\n", (double)open_timeval_diff.tv_sec + ((double)open_timeval_diff.tv_usec / (double)1000000.0)); + HDfprintf(file->logfp, "Open took: (%f s)\n", (double)open_timeval_diff.tv_sec + ((double)open_timeval_diff.tv_usec / (double)1000000.0f)); if(file->fa.flags & H5FD_LOG_TIME_STAT) - HDfprintf(file->logfp, "Stat took: (%f s)\n", (double)stat_timeval_diff.tv_sec + ((double)stat_timeval_diff.tv_usec / (double)1000000.0)); + HDfprintf(file->logfp, "Stat took: (%f s)\n", (double)stat_timeval_diff.tv_sec + ((double)stat_timeval_diff.tv_usec / (double)1000000.0f)); #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ @@ -734,7 +734,7 @@ H5FD_log_close(H5FD_t *_file) timeval_diff.tv_usec += 1000000; timeval_diff.tv_sec--; } /* end if */ - HDfprintf(file->logfp, "Close took: (%f s)\n", (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0)); + HDfprintf(file->logfp, "Close took: (%f s)\n", (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0f)); } /* end if */ #endif /* H5_HAVE_GETTIMEOFDAY */ @@ -1195,7 +1195,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr timeval_diff.tv_usec += 1000000; timeval_diff.tv_sec--; } /* end if */ - time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0); + time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0f); HDfprintf(file->logfp, " (%f s)\n", time_diff); /* Add to total seek time */ @@ -1284,7 +1284,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr timeval_diff.tv_usec += 1000000; timeval_diff.tv_sec--; } /* end if */ - time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0); + time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0f); HDfprintf(file->logfp, " (%f s)\n", time_diff); /* Add to total read time */ @@ -1401,7 +1401,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add timeval_diff.tv_usec += 1000000; timeval_diff.tv_sec--; } /* end if */ - time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0); + time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0f); HDfprintf(file->logfp, " (%f s)\n", time_diff); /* Add to total seek time */ @@ -1487,7 +1487,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add timeval_diff.tv_usec += 1000000; timeval_diff.tv_sec--; } /* end if */ - time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0); + time_diff = (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0f); HDfprintf(file->logfp, " (%f s)\n", time_diff); /* Add to total write time */ diff --git a/src/H5FDmpio.c b/src/H5FDmpio.c index cac101b..2db77c9 100644 --- a/src/H5FDmpio.c +++ b/src/H5FDmpio.c @@ -1013,8 +1013,8 @@ H5FD_mpio_open(const char *name, unsigned flags, hid_t fapl_id, _fa.info = MPI_INFO_NULL; /*default*/ fa = &_fa; } else { - fa = (const H5FD_mpio_fapl_t *)H5P_get_driver_info(plist); - assert(fa); + if(NULL == (fa = (const H5FD_mpio_fapl_t *)H5P_get_driver_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") } /* Duplicate communicator and Info object for use by this file. */ diff --git a/src/H5FDmpiposix.c b/src/H5FDmpiposix.c index 0d0b839..092cd24 100644 --- a/src/H5FDmpiposix.c +++ b/src/H5FDmpiposix.c @@ -600,8 +600,8 @@ H5FD_mpiposix_open(const char *name, unsigned flags, hid_t fapl_id, fa = &_fa; } /* end if */ else { - fa = H5P_get_driver_info(plist); - HDassert(fa); + if(NULL == (fa = (const H5FD_mpiposix_fapl_t *)H5P_get_driver_info(plist))) + HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") } /* end else */ /* Duplicate the communicator for use by this file. */ diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index c2add9a..c68c699 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -30,10 +30,6 @@ #include "h5tools_utils.h" #include "H5private.h" -#define SANITY_CHECK - -#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z)) - h5tool_format_t h5tools_dataformat = { 0, /*raw */ @@ -214,6 +210,12 @@ hbool_t h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, hsize_t *curr_pos/*total data element position*/, size_t ncols, hsize_t region_elmt_counter/*element counter*/, hsize_t elmt_counter); + +void h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims); + +void h5tools_dump_subsetting_header(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, struct subset_t *sset, int dims); + void h5tools_dump_init(void) { @@ -627,7 +629,11 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); +{ + HERROR(H5E_tools_g, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); + HGOTO_DONE(dimension_break); + //HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); +} H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) @@ -688,7 +694,7 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, h5tools_str_reset(buffer); h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin); - h5tools_print_dataspace(stream, buffer, info, ctx, region_space); + h5tools_print_dataspace(buffer, region_space); if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); @@ -1007,7 +1013,7 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, ctx->need_prefix = TRUE; h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin); - h5tools_print_dataspace(stream, buffer, info, ctx, region_space); + h5tools_print_dataspace(buffer, region_space); if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); @@ -2211,7 +2217,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ /* Check C variable-length string first. Are the two types equal? */ if (H5Tequal(tmp_type, str_type)) { h5tools_str_append(buffer, "H5T_C_S1;"); - goto done; + goto found_string_type; } /* Change the endianness and see if they're equal. */ @@ -2223,7 +2229,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ if (H5Tequal(tmp_type, str_type)) { h5tools_str_append(buffer, "H5T_C_S1;"); - goto done; + goto found_string_type; } /* If not equal to C variable-length string, check Fortran type. */ @@ -2238,7 +2244,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ /* Are the two types equal? */ if (H5Tequal(tmp_type, str_type)) { h5tools_str_append(buffer, "H5T_FORTRAN_S1;"); - goto done; + goto found_string_type; } /* Change the endianness and see if they're equal. */ @@ -2250,13 +2256,13 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ if (H5Tequal(tmp_type, str_type)) { h5tools_str_append(buffer, "H5T_FORTRAN_S1;"); - goto done; + goto found_string_type; } /* Type doesn't match any of above. */ h5tools_str_append(buffer, "unknown_one_character_type;"); - done: + found_string_type: h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); ctx->indent_level--; @@ -2307,7 +2313,10 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); ctx->indent_level++; { - char *ttag = H5Tget_tag(type); + char *ttag; + + if(NULL == (ttag = H5Tget_tag(type))) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_tag failed"); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, 0, 0); @@ -2316,8 +2325,7 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ h5tools_str_append(buffer, "OPAQUE_TAG \"%s\";", ttag); h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); - if (ttag) - HDfree(ttag); + HDfree(ttag); } ctx->indent_level--; @@ -2478,8 +2486,7 @@ CATCH *------------------------------------------------------------------------- */ int -h5tools_print_dataspace(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *info, - h5tools_context_t *ctx, hid_t space) +h5tools_print_dataspace(h5tools_str_t *buffer, hid_t space) { HERR_INIT(int, SUCCEED) hsize_t size[H5TOOLS_DUMP_MAX_RANK]; @@ -2769,7 +2776,7 @@ h5tools_dump_dataspace(FILE *stream, const h5tool_format_t *info, h5tools_str_append(&buffer, "%s ", h5tools_dump_header_format->dataspacebegin); - h5tools_print_dataspace(stream, &buffer, info, ctx, type); + h5tools_print_dataspace(&buffer, type); if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataspaceblockend); @@ -2841,7 +2848,6 @@ h5tools_print_fill_value(h5tools_str_t *buffer/*in,out*/, const h5tool_format_t { size_t size; hid_t n_type; - hsize_t nelmts = 1; void *buf = NULL; n_type = h5tools_get_native_type(type_id); @@ -3563,7 +3569,8 @@ h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims) for (i = 0; i < dims; i++) { h5tools_str_append(buffer, HSIZE_T_FORMAT, s[i]); - if (i + 1 != dims) h5tools_str_append(buffer, ", "); + if (i + 1 != dims) + h5tools_str_append(buffer, ", "); } } @@ -3866,7 +3873,7 @@ h5tools_dump_data(FILE *stream, const h5tool_format_t *info, buf = HDmalloc((size_t)alloc_size); HDassert(buf); - if (H5Aread(obj_id, p_type, buf) >= 0) + if (H5Aread(obj_id, p_type, buf) >= 0) { if (display_char && H5Tget_size(type) == 1 && H5Tget_class(type) == H5T_INTEGER) { /* * Print 1-byte integer data as an ASCII character string @@ -3895,6 +3902,7 @@ h5tools_dump_data(FILE *stream, const h5tool_format_t *info, } else datactx.need_prefix = TRUE; + } status = h5tools_dump_mem(stream, info, &datactx, obj_id, p_type, space, buf); if (display_char && H5Tget_size(type) == 1 && H5Tget_class(type) == H5T_INTEGER) { diff --git a/tools/lib/h5tools_dump.h b/tools/lib/h5tools_dump.h index 55e046b..86f9f99 100644 --- a/tools/lib/h5tools_dump.h +++ b/tools/lib/h5tools_dump.h @@ -67,8 +67,7 @@ H5TOOLS_DLL void h5tools_dump_data(FILE *stream, const h5tool_format_t *info, H5TOOLS_DLL int h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer/*in,out*/, const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, hid_t type, int object_search); -H5TOOLS_DLL int h5tools_print_dataspace(FILE *stream, h5tools_str_t *buffer/*in,out*/, - const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, +H5TOOLS_DLL int h5tools_print_dataspace(h5tools_str_t *buffer/*in,out*/, hid_t space); H5TOOLS_DLL int h5tools_print_enum(FILE *stream, h5tools_str_t *buffer/*in,out*/, const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, -- cgit v0.12