From 84ef7b0ad231923273dd5a1d9612e5d5f271968c Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 8 Feb 2011 16:40:24 -0500 Subject: [svn-r20066] Description: Bring r20065 from trunk to 1.8 branch: Bring changes from Coverity branch to trunk: r19975: Fixed potential mem leak at H5O_attr_open_by_name r19980: Fix coverity issue 792. Free tmp_env_prefix in H5Lexternal.c line 365 if it is not NULL but its contents are 0 when it goes out of scope. r20039: Eliminate warnings about nested extern and implicit declarations of parallel_print and address Coverity defects 712-781 by #including h5tools_utils.h in h5diff_array.c, h5diff_attr.c, h5diff_dset.c and h5diff_util.c. r20046: Purpose: Address TOCTOU warnings in h5jam and h5unjam Description: Coverity is afraid that the state of the input file could change between the call to stat() and the call to open(). This is called a time-of- check time-of-use (TOCTOU) vulnerability. Modified stat calls to fstat which uses an open file pointer so it (hopefully) won't complain any more. r20047: Addressed coverity issues 135-137, 462-464. Local pointers that needed to be freed in case of error were moved out of a switch statement in src/H5Tnative.c, set to NULL, and checked before freeing. Tested on: Mac OS X/32 10.6.6 (amazon) w/debug & production (h5committested on Coverity branch) --- src/H5FDlog.h | 4 +- src/H5Lexternal.c | 2 +- src/H5Oattribute.c | 47 ++++--- src/H5Tnative.c | 328 +++++++++++++++++++++++------------------------ tools/h5jam/h5jam.c | 46 +++---- tools/h5jam/h5unjam.c | 16 +-- tools/lib/h5diff.c | 5 +- tools/lib/h5diff_array.c | 12 +- tools/lib/h5diff_attr.c | 4 +- tools/lib/h5diff_dset.c | 5 +- tools/lib/h5diff_util.c | 5 +- 11 files changed, 239 insertions(+), 235 deletions(-) diff --git a/src/H5FDlog.h b/src/H5FDlog.h index bd1bbe2..ffc4df1 100644 --- a/src/H5FDlog.h +++ b/src/H5FDlog.h @@ -38,13 +38,13 @@ #define H5FD_LOG_FILE_IO (H5FD_LOG_FILE_READ|H5FD_LOG_FILE_WRITE) /* Flag for tracking "flavor" (type) of information stored at each byte */ #define H5FD_LOG_FLAVOR 0x00000020 -/* Flags for tracking total number of reads/writes/seeks */ +/* Flags for tracking total number of reads/writes/seeks/truncates */ #define H5FD_LOG_NUM_READ 0x00000040 #define H5FD_LOG_NUM_WRITE 0x00000080 #define H5FD_LOG_NUM_SEEK 0x00000100 #define H5FD_LOG_NUM_TRUNCATE 0x00000200 #define H5FD_LOG_NUM_IO (H5FD_LOG_NUM_READ|H5FD_LOG_NUM_WRITE|H5FD_LOG_NUM_SEEK|H5FD_LOG_NUM_TRUNCATE) -/* Flags for tracking time spent in open/read/write/seek/close */ +/* Flags for tracking time spent in open/stat/read/write/seek/close */ #define H5FD_LOG_TIME_OPEN 0x00000400 #define H5FD_LOG_TIME_STAT 0x00000800 #define H5FD_LOG_TIME_READ 0x00001000 diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 4700fee..89d9873 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -359,7 +359,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, if(H5L_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) { saved_env = (char *)H5MM_xfree(saved_env); HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename") - } + } /* end if */ ext_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, H5AC_dxpl_id); full_name = (char *)H5MM_xfree(full_name); diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index a64b6af..8bb3670 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -472,9 +472,10 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) { H5O_t *oh = NULL; /* Pointer to actual object header */ H5O_ainfo_t ainfo; /* Attribute information for object */ - H5A_t *ret_value; /* Return value */ - H5A_t *exist_attr = NULL; /* Opened attribute object */ + H5A_t *exist_attr = NULL; /* Existing opened attribute object */ + H5A_t *opened_attr = NULL; /* Newly opened attribute object */ htri_t found_open_attr = FALSE; /* Whether opened object is found */ + H5A_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_open_by_name) @@ -500,14 +501,14 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, name)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute") else if(found_open_attr == TRUE) { - if(NULL == (ret_value = H5A_copy(NULL, exist_attr))) + if(NULL == (opened_attr = H5A_copy(NULL, exist_attr))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") } /* end else if */ else { /* Check for attributes in dense storage */ if(H5F_addr_defined(ainfo.fheap_addr)) { /* Open attribute with dense storage */ - if(NULL == (ret_value = H5A_dense_open(loc->file, dxpl_id, &ainfo, name))) + if(NULL == (opened_attr = H5A_dense_open(loc->file, dxpl_id, &ainfo, name))) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "can't open attribute") } /* end if */ else { @@ -530,19 +531,26 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) /* Get attribute opened from object header */ HDassert(udata.attr); - ret_value = udata.attr; + opened_attr = udata.attr; } /* end else */ /* Mark datatype as being on disk now */ - if(H5T_set_loc(ret_value->shared->dt, loc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(opened_attr->shared->dt, loc->file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") - } /* end else */ + /* Set return value */ + ret_value = opened_attr; + done: if(oh && H5O_unprotect(loc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTUNPROTECT, NULL, "unable to release object header") + /* Release any resources, on error */ + if(NULL == ret_value && opened_attr) + if(H5A_close(opened_attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_attr_open_by_name() */ @@ -606,9 +614,10 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, { H5O_t *oh = NULL; /* Object header */ H5A_attr_iter_op_t attr_op; /* Attribute operator */ - H5A_t *exist_attr = NULL; /* Opened attribute object */ + H5A_t *exist_attr = NULL; /* Existing opened attribute object */ + H5A_t *opened_attr = NULL; /* Newly opened attribute object */ htri_t found_open_attr = FALSE; /* Whether opened object is found */ - H5A_t *ret_value = NULL; /* Return value */ + H5A_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_open_by_idx) @@ -620,7 +629,7 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, attr_op.u.lib_op = H5O_attr_open_by_idx_cb; /* Iterate over attributes to locate correct one */ - if(H5O_attr_iterate_real((hid_t)-1, loc, dxpl_id, idx_type, order, n, NULL, &attr_op, &ret_value) < 0) + if(H5O_attr_iterate_real((hid_t)-1, loc, dxpl_id, idx_type, order, n, NULL, &attr_op, &opened_attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_BADITER, NULL, "can't locate attribute") /* Protect the object header to iterate over */ @@ -630,29 +639,37 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, /* Find out whether it has already been opened. If it has, close the object * and make a copy of the already opened object to share the object info. */ - if(ret_value) { - if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, ret_value->shared->name)) < 0) + if(opened_attr) { + if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, opened_attr->shared->name)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute") /* If found that the attribute is already opened, make a copy of it * and close the object just opened. */ if(found_open_attr && exist_attr) { - if(H5A_close(ret_value) < 0) + if(H5A_close(opened_attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") - if(NULL == (ret_value = H5A_copy(NULL, exist_attr))) + if(NULL == (opened_attr = H5A_copy(NULL, exist_attr))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") } else { /* Mark datatype as being on disk now */ - if(H5T_set_loc(ret_value->shared->dt, loc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(opened_attr->shared->dt, loc->file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") } /* end if */ } /* end if */ + /* Set return value */ + ret_value = opened_attr; + done: if(oh && H5O_unprotect(loc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTUNPROTECT, NULL, "unable to release object header") + /* Release any resources, on error */ + if(NULL == ret_value && opened_attr) + if(H5A_close(opened_attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_attr_open_by_idx() */ diff --git a/src/H5Tnative.c b/src/H5Tnative.c index 5b685b1..3699757 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -94,8 +94,6 @@ H5T_init_native_interface(void) * Programmer: Raymond Lu * Oct 3, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ hid_t @@ -147,38 +145,39 @@ done: * Programmer: Raymond Lu * Oct 3, 2002 * - * Modifications: - * Raymond Lu - * 27 April 2010 - * I changed the way that the offset, alignment, and size of - * nested compound type are calculated by using H5T_cmp_offset. - * The old way had a bug in it (see bug #1850). - * *------------------------------------------------------------------------- */ -static H5T_t* +static H5T_t * H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size) { H5T_t *dt; /* Datatype to make native */ + H5T_t *super_type; /* Super type of VL, array and enum datatypes */ + H5T_t *nat_super_type; /* Native form of VL, array & enum super datatype */ + H5T_t *new_type = NULL; /* New native datatype */ + H5T_t *memb_type = NULL; /* Datatype of member */ + H5T_t **memb_list = NULL; /* List of compound member IDs */ + size_t *memb_offset = NULL; /* List of member offsets in compound type, including member size and alignment */ + char **comp_mname = NULL; /* List of member names in compound type */ + char *memb_name = NULL; /* Enum's member name */ + void *memb_value = NULL; /* Enum's member value */ + void *tmp_memb_value = NULL; /* Enum's member value */ + hsize_t *dims = NULL; /* Dimension sizes for array */ H5T_class_t h5_class; /* Class of datatype to make native */ size_t size; /* Size of datatype to make native */ size_t prec; /* Precision of datatype to make native */ int snmemb; /* Number of members in compound & enum types */ - unsigned nmemb; /* Number of members in compound & enum types */ - H5T_t *super_type; /* Super type of VL, array and enum datatypes */ - H5T_t *nat_super_type; /* Native form of VL, array & enum super datatype */ - H5T_t *new_type=NULL; /* New native datatype */ - unsigned i; /* Local index variable */ + unsigned nmemb = 0; /* Number of members in compound & enum types */ + unsigned u; /* Local index variable */ H5T_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5T_get_native_type, NULL) assert(dtype); - if((h5_class = H5T_get_class(dtype, FALSE)) == H5T_NO_CLASS) + if(H5T_NO_CLASS == (h5_class = H5T_get_class(dtype, FALSE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid class") - if((size = H5T_get_size(dtype)) == 0) + if(0 == (size = H5T_get_size(dtype))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid size") switch(h5_class) { @@ -186,35 +185,36 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig { H5T_sign_t sign; /* Signedness of integer type */ - if((sign = H5T_get_sign(dtype))==H5T_SGN_ERROR) + if(H5T_SGN_ERROR == (sign = H5T_get_sign(dtype))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid signess") prec = dtype->shared->u.atomic.prec; - if((ret_value = H5T_get_native_integer(prec, sign, direction, struct_align, offset, comp_size))==NULL) + if(NULL == (ret_value = H5T_get_native_integer(prec, sign, direction, struct_align, offset, comp_size))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve integer type") - } + } /* end case */ break; case H5T_FLOAT: - if((ret_value = H5T_get_native_float(size, direction, struct_align, offset, comp_size))==NULL) + if(NULL == (ret_value = H5T_get_native_float(size, direction, struct_align, offset, comp_size))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") break; case H5T_STRING: - if((ret_value=H5T_copy(dtype, H5T_COPY_TRANSIENT))==NULL) + if(NULL == (ret_value = H5T_copy(dtype, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") if(H5T_IS_VL_STRING(dtype->shared)) { /* Update size, offset and compound alignment for parent. */ - if(H5T_cmp_offset(comp_size, offset, sizeof(char *), (size_t)1, H5T_POINTER_COMP_ALIGN_g, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, sizeof(char *), (size_t)1, H5T_POINTER_COMP_ALIGN_g, struct_align) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") - } else { + } /* end if */ + else { /* Update size, offset and compound alignment for parent. */ - if(H5T_cmp_offset(comp_size, offset, sizeof(char), size, H5T_NATIVE_SCHAR_COMP_ALIGN_g, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, sizeof(char), size, H5T_NATIVE_SCHAR_COMP_ALIGN_g, struct_align) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") - } + } /* end else */ break; /* The time type will be supported in the future. Simply return "not supported" @@ -226,17 +226,17 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig { prec = dtype->shared->u.atomic.prec; - if((ret_value = H5T_get_native_bitfield(prec, direction, struct_align, offset, comp_size))==NULL) + if(NULL == (ret_value = H5T_get_native_bitfield(prec, direction, struct_align, offset, comp_size))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve integer for bitfield type") - } + } /* end case */ break; case H5T_OPAQUE: - if((ret_value=H5T_copy(dtype, H5T_COPY_TRANSIENT))==NULL) + if(NULL == (ret_value = H5T_copy(dtype, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") /* Update size, offset and compound alignment for parent. */ - if(H5T_cmp_offset(comp_size, offset, sizeof(char), size, H5T_NATIVE_SCHAR_COMP_ALIGN_g, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, sizeof(char), size, H5T_NATIVE_SCHAR_COMP_ALIGN_g, struct_align) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") break; @@ -246,11 +246,11 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig size_t ref_size; int not_equal; - if((ret_value=H5T_copy(dtype, H5T_COPY_TRANSIENT))==NULL) + if(NULL == (ret_value = H5T_copy(dtype, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") /* Decide if the data type is object or dataset region reference. */ - if(NULL==(dt=(H5T_t *)H5I_object(H5T_STD_REF_OBJ_g))) + if(NULL == (dt = (H5T_t *)H5I_object(H5T_STD_REF_OBJ_g))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type") not_equal = H5T_cmp(ret_value, dt, FALSE); @@ -258,69 +258,65 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig if(!not_equal) { align = H5T_HOBJREF_COMP_ALIGN_g; ref_size = sizeof(hobj_ref_t); - } else { + } /* end if */ + else { align = H5T_HDSETREGREF_COMP_ALIGN_g; ref_size = sizeof(hdset_reg_ref_t); - } + } /* end else */ - if(H5T_cmp_offset(comp_size, offset, ref_size, (size_t)1, align, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, ref_size, (size_t)1, align, struct_align) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") - } + } /* end case */ break; case H5T_COMPOUND: { - H5T_t *memb_type; /* Datatype of member */ - H5T_t **memb_list; /* List of compound member IDs */ - size_t *memb_offset; /* List of member offsets in compound type, including member size and alignment */ - size_t children_size=0;/* Total size of compound members */ - size_t children_st_align=0; /* The max alignment among compound members. This'll be the compound alignment */ - char **comp_mname; /* List of member names in compound type */ - - if((snmemb = H5T_get_nmembers(dtype))<=0) + size_t children_size = 0;/* Total size of compound members */ + size_t children_st_align = 0; /* The max alignment among compound members. This'll be the compound alignment */ + + if((snmemb = H5T_get_nmembers(dtype)) <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "compound data type doesn't have any member") - H5_ASSIGN_OVERFLOW(nmemb,snmemb,int,unsigned); + H5_ASSIGN_OVERFLOW(nmemb, snmemb, int, unsigned); - if((memb_list = (H5T_t**)H5MM_malloc(nmemb*sizeof(H5T_t*)))==NULL) + if(NULL == (memb_list = (H5T_t **)H5MM_calloc(nmemb * sizeof(H5T_t *)))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot allocate memory") - if((memb_offset = (size_t*)H5MM_calloc(nmemb*sizeof(size_t)))==NULL) + if(NULL == (memb_offset = (size_t *)H5MM_calloc(nmemb * sizeof(size_t)))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot allocate memory") - if((comp_mname = (char**)H5MM_malloc(nmemb*sizeof(char*)))==NULL) + if(NULL == (comp_mname = (char **)H5MM_calloc(nmemb * sizeof(char *)))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot allocate memory") /* Construct child compound type and retrieve a list of their IDs, offsets, total size, and alignment for compound type. */ - for(i=0; iH5Tget_precision(H5T_NATIVE_LONG)) { - match=H5T_NATIVE_INT_MATCH_LLONG; + if(prec > H5Tget_precision(H5T_NATIVE_LONG)) { + match = H5T_NATIVE_INT_MATCH_LLONG; native_size = sizeof(long long); - } else if(prec>H5Tget_precision(H5T_NATIVE_INT)) { - match=H5T_NATIVE_INT_MATCH_LONG; + } else if(prec > H5Tget_precision(H5T_NATIVE_INT)) { + match = H5T_NATIVE_INT_MATCH_LONG; native_size = sizeof(long); - } else if(prec>H5Tget_precision(H5T_NATIVE_SHORT)) { - match=H5T_NATIVE_INT_MATCH_INT; + } else if(prec > H5Tget_precision(H5T_NATIVE_SHORT)) { + match = H5T_NATIVE_INT_MATCH_INT; native_size = sizeof(int); - } else if(prec>H5Tget_precision(H5T_NATIVE_SCHAR)) { - match=H5T_NATIVE_INT_MATCH_SHORT; + } else if(prec > H5Tget_precision(H5T_NATIVE_SCHAR)) { + match = H5T_NATIVE_INT_MATCH_SHORT; native_size = sizeof(short); } else { - match=H5T_NATIVE_INT_MATCH_CHAR; + match = H5T_NATIVE_INT_MATCH_CHAR; native_size = sizeof(char); } } @@ -605,7 +612,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, /* Set the appropriate native datatype information */ switch(match) { case H5T_NATIVE_INT_MATCH_CHAR: - if(sign==H5T_SGN_2) + if(sign == H5T_SGN_2) tid = H5T_NATIVE_SCHAR; else tid = H5T_NATIVE_UCHAR; @@ -614,7 +621,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, break; case H5T_NATIVE_INT_MATCH_SHORT: - if(sign==H5T_SGN_2) + if(sign == H5T_SGN_2) tid = H5T_NATIVE_SHORT; else tid = H5T_NATIVE_USHORT; @@ -622,7 +629,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, break; case H5T_NATIVE_INT_MATCH_INT: - if(sign==H5T_SGN_2) + if(sign == H5T_SGN_2) tid = H5T_NATIVE_INT; else tid = H5T_NATIVE_UINT; @@ -631,7 +638,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, break; case H5T_NATIVE_INT_MATCH_LONG: - if(sign==H5T_SGN_2) + if(sign == H5T_SGN_2) tid = H5T_NATIVE_LONG; else tid = H5T_NATIVE_ULONG; @@ -640,7 +647,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, break; case H5T_NATIVE_INT_MATCH_LLONG: - if(sign==H5T_SGN_2) + if(sign == H5T_SGN_2) tid = H5T_NATIVE_LLONG; else tid = H5T_NATIVE_ULLONG; @@ -654,21 +661,20 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, } /* end switch */ /* Create new native type */ - assert(tid>=0); - if(NULL==(dt=(H5T_t *)H5I_object(tid))) + HDassert(tid >= 0); + if(NULL == (dt = (H5T_t *)H5I_object(tid))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type") - if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL) + if(NULL == (ret_value = H5T_copy(dt, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot copy type") /* compute size and offset of compound type member. */ - if(H5T_cmp_offset(comp_size, offset, native_size, (size_t)1, align, struct_align)<0) + if(H5T_cmp_offset(comp_size, offset, native_size, (size_t)1, align, struct_align) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") done: FUNC_LEAVE_NOAPI(ret_value) -} - +} /* end H5T_get_native_integer() */ /*------------------------------------------------------------------------- @@ -683,8 +689,6 @@ done: * Programmer: Raymond Lu * Oct 3, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ static H5T_t* @@ -810,8 +814,6 @@ done: * Programmer: Raymond Lu * 1 December 2009 * - * Modifications: - * *------------------------------------------------------------------------- */ static H5T_t* @@ -824,7 +826,7 @@ H5T_get_native_bitfield(size_t prec, H5T_direction_t direction, size_t *struct_a size_t native_size=0; /* Datatype size of the native type */ H5T_t *ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5T_get_native_bitfield, NULL); + FUNC_ENTER_NOAPI(H5T_get_native_bitfield, NULL) if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) { if(prec<=H5Tget_precision(H5T_NATIVE_B8)) { @@ -899,8 +901,6 @@ done: * Programmer: Raymond Lu * December 10, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t diff --git a/tools/h5jam/h5jam.c b/tools/h5jam/h5jam.c index 17b1384..d6d3d8f 100644 --- a/tools/h5jam/h5jam.c +++ b/tools/h5jam/h5jam.c @@ -238,41 +238,33 @@ main (int argc, const char *argv[]) exit (EXIT_FAILURE); } - H5Pclose (plist); - H5Fclose (ifile); + H5Pclose(plist); + H5Fclose(ifile); - ufid = HDopen (ub_file, O_RDONLY, 0); - - if (ufid < 0) - { + ufid = HDopen(ub_file, O_RDONLY, 0); + if(ufid < 0) { error_msg("unable to open user block file \"%s\"\n", ub_file); exit (EXIT_FAILURE); } - res = stat (ub_file, &sbuf); - - if (res < 0) - { + res = HDfstat(ufid, &sbuf); + if(res < 0) { error_msg("Can't stat file \"%s\"\n", ub_file); exit (EXIT_FAILURE); } fsize = sbuf.st_size; - h5fid = HDopen (input_file, O_RDONLY, 0); - - if (h5fid < 0) - { + h5fid = HDopen(input_file, O_RDONLY, 0); + if(h5fid < 0) { error_msg("unable to open HDF5 file for read \"%s\"\n", input_file); exit (EXIT_FAILURE); } - res = stat (input_file, &sbuf2); - - if (res < 0) - { + res = HDfstat(h5fid, &sbuf2); + if(res < 0) { error_msg("Can't stat file \"%s\"\n", input_file); exit (EXIT_FAILURE); } @@ -396,19 +388,15 @@ copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, ssize_t toend; ssize_t fromend; - if (startin > startout) - { + if(startin > startout) { /* this case is prohibited */ error_msg("copy_some_to_file: panic: startin > startout?\n"); exit (EXIT_FAILURE); } - if (limit < 0) - { - res = fstat (infid, &sbuf); - - if (res < 0) - { + if(limit < 0) { + res = HDfstat(infid, &sbuf); + if(res < 0) { error_msg("Can't stat file \n"); exit (EXIT_FAILURE); } @@ -416,14 +404,10 @@ copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, howmuch = sbuf.st_size; } else - { howmuch = limit; - } - if (howmuch == 0) - { + if(howmuch == 0) return 0; - } /* assert (howmuch > 0) */ diff --git a/tools/h5jam/h5unjam.c b/tools/h5jam/h5unjam.c index 8e31ce1..fd79e1a 100644 --- a/tools/h5jam/h5unjam.c +++ b/tools/h5jam/h5unjam.c @@ -221,22 +221,20 @@ main(int argc, const char *argv[]) } - res = stat(input_file, &sbuf); + ifid = HDopen(input_file,O_RDONLY,0); + if(ifid < 0) { + error_msg("unable to open input HDF5 file \"%s\"\n", input_file); + exit(EXIT_FAILURE); + } - if (res < 0) { + res = HDfstat(ifid, &sbuf); + if(res < 0) { error_msg("Can't stat file \"%s\"\n", input_file); exit(EXIT_FAILURE); } fsize = sbuf.st_size; - ifid = HDopen(input_file,O_RDONLY,0); - - if (ifid < 0) { - error_msg("unable to open input HDF5 file \"%s\"\n", input_file); - exit(EXIT_FAILURE); - } - if (do_delete && (ub_file != NULL)) { error_msg("??\"%s\"\n", ub_file); exit(EXIT_FAILURE); diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 640a20a..5f406cf 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -14,11 +14,12 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include + #include "H5private.h" -#include "h5diff.h" -#include "ph5diff.h" #include "h5tools.h" #include "h5tools_utils.h" +#include "h5diff.h" +#include "ph5diff.h" /* * Debug printf macros. The prefix allows output filtering by test scripts. diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 482f9bd..1c2cfa9 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -14,15 +14,15 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include -#include "h5diff.h" -#include "ph5diff.h" -#include "H5private.h" -#include "h5tools.h" - - #include #include +#include "H5private.h" +#include "h5tools.h" +#include "h5tools_utils.h" +#include "h5diff.h" +#include "ph5diff.h" + /*------------------------------------------------------------------------- * printf formatting diff --git a/tools/lib/h5diff_attr.c b/tools/lib/h5diff_attr.c index ad6f45b..7e5fb04 100644 --- a/tools/lib/h5diff_attr.c +++ b/tools/lib/h5diff_attr.c @@ -13,9 +13,11 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include "H5private.h" #include "h5tools.h" +#include "h5tools_utils.h" #include "h5diff.h" -#include "H5private.h" + /*------------------------------------------------------------------------- * Function: diff_attr diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index 0f482b6..f8fc493 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -13,10 +13,11 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "h5diff.h" -#include "ph5diff.h" #include "H5private.h" #include "h5tools.h" +#include "h5tools_utils.h" +#include "h5diff.h" +#include "ph5diff.h" /*------------------------------------------------------------------------- diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index bc127a2..48e0ecb 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -13,10 +13,11 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "h5diff.h" -#include "ph5diff.h" #include "H5private.h" #include "h5tools.h" +#include "h5tools_utils.h" +#include "h5diff.h" +#include "ph5diff.h" -- cgit v0.12