From 1208e94eff8223d5c68bd7d50c4b885df222122a Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 17 Jan 2003 15:34:14 -0500 Subject: [svn-r6296] Purpose: Code cleanup Description: Reduce warnings on Windows Platforms tested: FreeBSD 4.7 (sleipnir) --- perform/overhead.c | 10 +++++----- src/H5D.c | 36 +++++++++++++++++++++--------------- src/H5Distore.c | 5 +++-- src/H5FD.c | 6 +++--- src/H5Fistore.c | 5 +++-- src/H5Sall.c | 3 ++- src/H5Shyper.c | 20 +++++++++++++------- src/H5Spoint.c | 3 ++- src/H5Sselect.c | 18 ++++++++++++++++-- src/H5Tconv.c | 13 +++++-------- test/big.c | 12 ++++++------ test/fillval.c | 2 +- tools/lib/h5tools.h | 2 +- tools/misc/h5repart.c | 15 ++++++++------- 14 files changed, 89 insertions(+), 61 deletions(-) diff --git a/perform/overhead.c b/perform/overhead.c index 9edacc9..0066255 100644 --- a/perform/overhead.c +++ b/perform/overhead.c @@ -229,7 +229,7 @@ test(fill_t fill_style, const double splits[], /* workaround for a bug in the Metrowerks version 6.0 open function */ - if ((fd=open(FILE_NAME_1, O_RDONLY))<0) goto error; + if ((fd=HDopen(FILE_NAME_1, O_RDONLY, 0666))<0) goto error; #endif for (i=1; i<=cur_size[0]; i++) { @@ -246,11 +246,11 @@ test(fill_t fill_style, const double splits[], hs_start[0] = i%2 ? i/2 : cur_size[0]-i/2; break; case FILL_OUTWARD: - j = (cur_size[0]-i)+1; + j = (int)(cur_size[0]-i)+1; hs_start[0] = j%2 ? j/2 : (hssize_t)cur_size[0]-j/2; break; case FILL_RANDOM: - for (j=rand()%cur_size[0]; had[j]; j=(j+1)%cur_size[0]) /*void*/; + for (j=HDrand()%(int)cur_size[0]; had[j]; j=(j+1)%(int)cur_size[0]) /*void*/; hs_start[0] = j; had[j] = 1; break; @@ -326,7 +326,7 @@ test(fill_t fill_style, const double splits[], #if !defined( __MWERKS__) - close(fd); + HDclose(fd); #endif return 0; @@ -339,7 +339,7 @@ test(fill_t fill_style, const double splits[], H5Pclose(xfer); H5Fclose(file); free(had); - close(fd); + HDclose(fd); return 1; } diff --git a/src/H5D.c b/src/H5D.c index 1037f4b..8b312df 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -1926,21 +1926,27 @@ H5D_create(H5G_entry_t *loc, const char *name, const H5T_t *type, break; case H5D_COMPACT: - /* - * Compact dataset is stored in dataset object header message of - * layout. - */ - new_dset->layout.size = H5S_get_simple_extent_npoints(space) * - H5T_get_size(type); - /* Verify data size is smaller than maximum header message size - * (64KB) minus other layout message fields. - */ - comp_data_size=H5O_MAX_SIZE-H5O_layout_meta_size(file, &(new_dset->layout)); - if(new_dset->layout.size > comp_data_size) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "compact dataset size is bigger than header message maximum size"); - if ((ndims=H5S_get_simple_extent_dims(space, new_dset->layout.dim, max_dim))<0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize dimension size of compact dataset storage"); - /* remember to check if size is small enough to fit header message */ + { + hssize_t tmp_size; /* Temporary holder for raw data size */ + + /* + * Compact dataset is stored in dataset object header message of + * layout. + */ + tmp_size = H5S_get_simple_extent_npoints(space) * + H5T_get_size(type); + H5_ASSIGN_OVERFLOW(new_dset->layout.size,tmp_size,hssize_t,size_t); + /* Verify data size is smaller than maximum header message size + * (64KB) minus other layout message fields. + */ + comp_data_size=H5O_MAX_SIZE-H5O_layout_meta_size(file, &(new_dset->layout)); + if(new_dset->layout.size > comp_data_size) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "compact dataset size is bigger than header message maximum size"); + if ((ndims=H5S_get_simple_extent_dims(space, new_dset->layout.dim, max_dim))<0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize dimension size of compact dataset storage"); + /* remember to check if size is small enough to fit header message */ + + } break; diff --git a/src/H5Distore.c b/src/H5Distore.c index 5278554..aa88704 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -2431,7 +2431,7 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, /* Check if there are filters which need to be applied to the chunk */ if (pline.nfilters>0) { unsigned filter_mask=0; - size_t buf_size=chunk_size; + size_t buf_size=(size_t)chunk_size; size_t nbytes=(size_t)chunk_size; /* Push the chunk through the filters */ @@ -2476,7 +2476,8 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, udata.mesg = *layout; udata.key.filter_mask = 0; udata.addr = HADDR_UNDEF; - udata.key.nbytes = chunk_size; + H5_CHECK_OVERFLOW(chunk_size,hsize_t,size_t); + udata.key.nbytes = (size_t)chunk_size; for (u=0; undims; u++) udata.key.offset[u] = chunk_offset[u]; diff --git a/src/H5FD.c b/src/H5FD.c index 3ba0739..7c2c701 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -1786,7 +1786,7 @@ H5FD_free(H5FD_t *file, H5FD_mem_t type, haddr_t addr, hsize_t size) size_t new_accum_size; /* Size of new accumulator buffer */ /* Calculate the size of the overlap with the accumulator, etc. */ - overlap_size=(addr+size)-file->accum_loc; + H5_ASSIGN_OVERFLOW(overlap_size,(addr+size)-file->accum_loc,haddr_t,size_t); new_accum_size=file->accum_size-overlap_size; /* Move the accumulator buffer information to eliminate the freed block */ @@ -1800,7 +1800,7 @@ H5FD_free(H5FD_t *file, H5FD_mem_t type, haddr_t addr, hsize_t size) /* Block to free must start within the accumulator */ else { /* Calculate the size of the overlap with the accumulator */ - overlap_size=(file->accum_loc+file->accum_size)-addr; + H5_ASSIGN_OVERFLOW(overlap_size,(file->accum_loc+file->accum_size)-addr,haddr_t,size_t); /* Block to free is in the middle of the accumulator */ if(H5F_addr_lt(addr,file->accum_loc+file->accum_size)) { @@ -1809,7 +1809,7 @@ H5FD_free(H5FD_t *file, H5FD_mem_t type, haddr_t addr, hsize_t size) /* Calculate the address & size of the tail to write */ tail_addr=addr+size; - tail_size=(file->accum_loc+file->accum_size)-tail_addr; + H5_ASSIGN_OVERFLOW(tail_size,(file->accum_loc+file->accum_size)-tail_addr,haddr_t,size_t); /* Write out the part of the accumulator after the block to free */ if (H5FD_write(file, H5FD_MEM_DEFAULT, H5P_DATASET_XFER_DEFAULT, tail_addr, tail_size, file->meta_accum+(tail_addr-file->accum_loc))<0) diff --git a/src/H5Fistore.c b/src/H5Fistore.c index 5278554..aa88704 100644 --- a/src/H5Fistore.c +++ b/src/H5Fistore.c @@ -2431,7 +2431,7 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, /* Check if there are filters which need to be applied to the chunk */ if (pline.nfilters>0) { unsigned filter_mask=0; - size_t buf_size=chunk_size; + size_t buf_size=(size_t)chunk_size; size_t nbytes=(size_t)chunk_size; /* Push the chunk through the filters */ @@ -2476,7 +2476,8 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, udata.mesg = *layout; udata.key.filter_mask = 0; udata.addr = HADDR_UNDEF; - udata.key.nbytes = chunk_size; + H5_CHECK_OVERFLOW(chunk_size,hsize_t,size_t); + udata.key.nbytes = (size_t)chunk_size; for (u=0; undims; u++) udata.key.offset[u] = chunk_offset[u]; diff --git a/src/H5Sall.c b/src/H5Sall.c index bc7a162..a8e5f40 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -646,7 +646,8 @@ H5S_all_get_seq_list(const H5S_t UNUSED *space, unsigned UNUSED flags, H5S_sel_i /* Compute the offset in the dataset */ off[0]=iter->all.offset*elem_size; - len[0]=MIN(maxbytes,bytes_left); + H5_CHECK_OVERFLOW(bytes_left,hsize_t,size_t); + len[0]=MIN(maxbytes,(size_t)bytes_left); /* Should only need one sequence for 'all' selections */ *nseq=1; diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 25e52c8..4ed0b2d 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -5099,7 +5099,8 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, ispan=iter->hyp.span; /* Set the amount of elements to perform I/O on, etc. */ - start_io_bytes_left=io_bytes_left=MIN(maxbytes,(iter->hyp.elmt_left*elem_size)); + H5_CHECK_OVERFLOW( (iter->hyp.elmt_left*elem_size) ,hsize_t,size_t); + start_io_bytes_left=io_bytes_left=MIN(maxbytes,(size_t)(iter->hyp.elmt_left*elem_size)); nelem=io_bytes_left/elem_size; /* Compute the cumulative size of dataspace dimensions */ @@ -5563,10 +5564,11 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, size_t leftover; /* The number of elements left over from the last sequence */ /* Calculate the number of elements left in the sequence */ + H5_CHECK_OVERFLOW( tdiminfo[fast_dim].block-(iter->hyp.off[fast_dim]-tdiminfo[fast_dim].start) ,hsize_t,size_t); if(tdiminfo[fast_dim].stride==1) - leftover=tdiminfo[fast_dim].block-(iter->hyp.off[fast_dim]-tdiminfo[fast_dim].start); + leftover=(size_t)(tdiminfo[fast_dim].block-(iter->hyp.off[fast_dim]-tdiminfo[fast_dim].start)); else - leftover=tdiminfo[fast_dim].block-((iter->hyp.off[fast_dim]-tdiminfo[fast_dim].start)%tdiminfo[fast_dim].stride); + leftover=(size_t)(tdiminfo[fast_dim].block-((iter->hyp.off[fast_dim]-tdiminfo[fast_dim].start)%tdiminfo[fast_dim].stride)); /* Make certain that we don't write too many */ actual_elem=MIN(leftover,io_left); @@ -5651,7 +5653,8 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, fast_dim_offset=fast_dim_start+sel_off[fast_dim]; /* Compute the number of blocks which would fit into the buffer */ - tot_blk_count=io_left/fast_dim_block; + H5_CHECK_OVERFLOW(io_left/fast_dim_block,hsize_t,size_t); + tot_blk_count=(size_t)(io_left/fast_dim_block); /* Don't go over the maximum number of sequences allowed */ tot_blk_count=MIN(tot_blk_count,(maxseq-curr_seq)); @@ -5748,7 +5751,8 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, } /* end if */ /* Compute the number of entire rows to read in */ - curr_rows=total_rows=tot_blk_count/tdiminfo[fast_dim].count; + H5_CHECK_OVERFLOW( tot_blk_count/tdiminfo[fast_dim].count ,hsize_t,size_t); + curr_rows=total_rows=(size_t)(tot_blk_count/tdiminfo[fast_dim].count); /* Reset copy of number of blocks in fastest dimension */ H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count,hsize_t,size_t); @@ -5910,10 +5914,12 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, /* Adjust the number of blocks & elements left to transfer */ /* Decrement number of elements left */ - io_left -= actual_elem*(total_rows*tdiminfo[fast_dim].count); + H5_CHECK_OVERFLOW( actual_elem*(total_rows*tdiminfo[fast_dim].count) ,hsize_t,size_t); + io_left -= (size_t)(actual_elem*(total_rows*tdiminfo[fast_dim].count)); /* Decrement number of blocks left */ - tot_blk_count -= (total_rows*tdiminfo[fast_dim].count); + H5_CHECK_OVERFLOW( (total_rows*tdiminfo[fast_dim].count) ,hsize_t,size_t); + tot_blk_count -= (size_t)(total_rows*tdiminfo[fast_dim].count); /* Read in partial row of blocks */ if(io_left>0 && curr_seqselect.get_npoints)(file_space)*elmt_size; +#ifndef NDEBUG + { + hsize_t tmp_maxbytes=(*file_space->select.get_npoints)(file_space)*elmt_size; + H5_ASSIGN_OVERFLOW(maxbytes,tmp_maxbytes,hsize_t,size_t); + } +#else /* NDEBUG */ + maxbytes=(size_t)((*file_space->select.get_npoints)(file_space)*elmt_size); +#endif /* NDEBUG */ /* Initialize sequence counts */ curr_mem_seq=curr_file_seq=0; @@ -1443,7 +1450,14 @@ H5S_select_write(H5F_t *f, H5O_layout_t *layout, H5P_genplist_t *dc_plist, mem_iter_init=1; /* Memory selection iteration info has been initialized */ /* Get number of bytes in selection */ - maxbytes=(*file_space->select.get_npoints)(file_space)*elmt_size; +#ifndef NDEBUG + { + hsize_t tmp_maxbytes=(*file_space->select.get_npoints)(file_space)*elmt_size; + H5_ASSIGN_OVERFLOW(maxbytes,tmp_maxbytes,hsize_t,size_t); + } +#else /* NDEBUG */ + maxbytes=(size_t)((*file_space->select.get_npoints)(file_space)*elmt_size); +#endif /* NDEBUG */ /* Initialize sequence counts */ curr_mem_seq=curr_file_seq=0; diff --git a/src/H5Tconv.c b/src/H5Tconv.c index a1df8e8..affa795 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -2272,16 +2272,13 @@ H5T_conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts, uint8_t *tmp=bg_ptr; UINT32DECODE(tmp, bg_seq_len); if(bg_seq_len>0) { - if(tmp_buf_sizeu.vlen.f, (const uint8_t **)&tmp, - &(bg_hobjid.addr)); + H5F_addr_decode(dst->u.vlen.f, (const uint8_t **)&tmp, &(bg_hobjid.addr)); INT32DECODE(tmp, bg_hobjid.idx); if(H5HG_read(dst->u.vlen.f,&bg_hobjid,tmp_buf)==NULL) HGOTO_ERROR (H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL sequence into background buffer"); diff --git a/test/big.c b/test/big.c index f26bb71..f9733fe 100644 --- a/test/big.c +++ b/test/big.c @@ -79,12 +79,12 @@ is_sparse(void) int fd; h5_stat_t sb; - if ((fd=open("x.h5", O_RDWR|O_TRUNC|O_CREAT, 0666))<0) return 0; - if (lseek(fd, (off_t)(1024*1024), SEEK_SET)!=1024*1024) return 0; - if (5!=write(fd, "hello", 5)) return 0; - if (close(fd)<0) return 0; - if (stat("x.h5", &sb)<0) return 0; - if (unlink("x.h5")<0) return 0; + if ((fd=HDopen("x.h5", O_RDWR|O_TRUNC|O_CREAT, 0666))<0) return 0; + if (HDlseek(fd, (off_t)(1024*1024), SEEK_SET)!=1024*1024) return 0; + if (5!=HDwrite(fd, "hello", 5)) return 0; + if (HDclose(fd)<0) return 0; + if (HDstat("x.h5", &sb)<0) return 0; + if (HDunlink("x.h5")<0) return 0; #ifdef H5_HAVE_STAT_ST_BLOCKS return ((unsigned long)sb.st_blocks*512 < (unsigned long)sb.st_size); #else diff --git a/test/fillval.c b/test/fillval.c index d15bfc5..455b8ed 100644 --- a/test/fillval.c +++ b/test/fillval.c @@ -689,7 +689,7 @@ test_rdwr_cases(hid_t file, hid_t dcpl, const char *dname, void *_fillval, (hssize_t)((size_t)(nelmts*sizeof(comp_datatype)))); buf_c = (comp_datatype*)calloc((size_t)nelmts,sizeof(comp_datatype)); for (i=0; i