From c581a0723521cd20d62f16af39457106735a8629 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Mon, 20 May 2002 08:39:57 -0500 Subject: [svn-r5439] Purpose: Code cleanup Description: Change variable casts to use H5_ASSIGN_OVERFLOW, or check for overflow before the cast with H5_CHECK_OVERFLOW. Platforms tested: FreeBSD 4.5 (sleipnir) --- src/H5Dcontig.c | 8 ++++---- src/H5Fcontig.c | 8 ++++---- src/H5Shyper.c | 39 ++++++++++++++++++++------------------- src/H5Tvlen.c | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 301aae9..e80a67f 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -432,7 +432,7 @@ H5F_contig_readv(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, /* Compute the size of the sieve buffer */ /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Update local copies of sieve information */ sieve_start=f->shared->sieve_loc; @@ -494,7 +494,7 @@ H5F_contig_readv(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, rel_eoa=abs_eoa-f->shared->base_addr; /* Compute the size of the sieve buffer */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Read the new sieve buffer */ if (H5F_block_read(f, type, f->shared->sieve_loc, f->shared->sieve_size, dxpl_id, f->shared->sieve_buf)<0) { @@ -912,7 +912,7 @@ H5F_contig_writev(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, /* Compute the size of the sieve buffer */ /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Update local copies of sieve information */ sieve_start=f->shared->sieve_loc; @@ -979,7 +979,7 @@ H5F_contig_writev(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, rel_eoa=abs_eoa-f->shared->base_addr; /* Compute the size of the sieve buffer */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Check if there is any point in reading the data from the file */ if(f->shared->sieve_size>size) { diff --git a/src/H5Fcontig.c b/src/H5Fcontig.c index 301aae9..e80a67f 100644 --- a/src/H5Fcontig.c +++ b/src/H5Fcontig.c @@ -432,7 +432,7 @@ H5F_contig_readv(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, /* Compute the size of the sieve buffer */ /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Update local copies of sieve information */ sieve_start=f->shared->sieve_loc; @@ -494,7 +494,7 @@ H5F_contig_readv(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, rel_eoa=abs_eoa-f->shared->base_addr; /* Compute the size of the sieve buffer */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Read the new sieve buffer */ if (H5F_block_read(f, type, f->shared->sieve_loc, f->shared->sieve_size, dxpl_id, f->shared->sieve_buf)<0) { @@ -912,7 +912,7 @@ H5F_contig_writev(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, /* Compute the size of the sieve buffer */ /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Update local copies of sieve information */ sieve_start=f->shared->sieve_loc; @@ -979,7 +979,7 @@ H5F_contig_writev(H5F_t *f, hsize_t _max_data, H5FD_mem_t type, haddr_t _addr, rel_eoa=abs_eoa-f->shared->base_addr; /* Compute the size of the sieve buffer */ - f->shared->sieve_size=(size_t)MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)); + H5_ASSIGN_OVERFLOW(f->shared->sieve_size,MIN(rel_eoa-f->shared->sieve_loc,MIN(max_data,f->shared->sieve_buf_size)),hsize_t,size_t); /* Check if there is any point in reading the data from the file */ if(f->shared->sieve_size>size) { diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 663817e..fda1b07 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -909,7 +909,8 @@ H5S_hyper_fread_opt (H5F_t *f, const struct H5O_layout_t *layout, leftover=file_space->select.sel_info.hslab.diminfo[fast_dim].block-((file_iter->hyp.off[fast_dim]-file_space->select.sel_info.hslab.diminfo[fast_dim].start)%file_space->select.sel_info.hslab.diminfo[fast_dim].stride); /* Make certain that we don't read too many */ - actual_read=(size_t)MIN(leftover,io_left); + H5_CHECK_OVERFLOW(leftover,hsize_t,size_t); + actual_read=MIN((size_t)leftover,io_left); actual_bytes=actual_read*elmt_size; /* Copy the location of the point to get */ @@ -992,7 +993,7 @@ H5S_hyper_fread_opt (H5F_t *f, const struct H5O_layout_t *layout, fast_dim_offset=fast_dim_start+file_space->select.offset[fast_dim]; /* Compute the number of blocks which would fit into the buffer */ - tot_blk_count=(size_t)io_left/(size_t)fast_dim_block; + H5_ASSIGN_OVERFLOW(tot_blk_count,(io_left/fast_dim_block),hsize_t,size_t); /* Compute the amount to wrap at the end of each row */ for(i=0; iselect.sel_info.hslab.diminfo[fast_dim].block-((file_iter->hyp.off[fast_dim]-file_space->select.sel_info.hslab.diminfo[fast_dim].start)%file_space->select.sel_info.hslab.diminfo[fast_dim].stride); /* Make certain that we don't write too many */ - actual_write=(size_t)MIN(leftover,io_left); + H5_CHECK_OVERFLOW(leftover,hsize_t,size_t); + actual_write=MIN((size_t)leftover,io_left); actual_bytes=actual_write*elmt_size; /* Copy the location of the point to get */ @@ -2016,7 +2018,7 @@ H5S_hyper_fwrite_opt (H5F_t *f, const struct H5O_layout_t *layout, fast_dim_offset=fast_dim_start+file_space->select.offset[fast_dim]; /* Compute the number of blocks which would fit into the buffer */ - tot_blk_count=(size_t)io_left/(size_t)fast_dim_block; + H5_ASSIGN_OVERFLOW(tot_blk_count,(io_left/fast_dim_block),hsize_t,size_t); /* Compute the amount to wrap at the end of each row */ for(i=0; ihyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride!=0 || ((mem_iter->hyp.off[fast_dim]!=mem_space->select.sel_info.hslab.diminfo[fast_dim].start) && mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1)) { - size_t leftover; /* The number of elements left over from the last sequence */ + hsize_t leftover; /* The number of elements left over from the last sequence */ /* Calculate the number of elements left in the sequence */ if(mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1) - leftover=(size_t)mem_space->select.sel_info.hslab.diminfo[fast_dim].block - -(size_t)(mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start); + leftover=mem_space->select.sel_info.hslab.diminfo[fast_dim].block-(mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start); else - leftover=(size_t)mem_space->select.sel_info.hslab.diminfo[fast_dim].block - -(size_t)((mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride); + leftover=mem_space->select.sel_info.hslab.diminfo[fast_dim].block-((mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride); /* Make certain that we don't write too many */ - actual_read=MIN(leftover,io_left); + H5_CHECK_OVERFLOW(leftover,hsize_t,size_t); + actual_read=MIN((size_t)leftover,io_left); actual_bytes=actual_read*elmt_size; /* Copy the location of the point to get */ @@ -2947,7 +2948,7 @@ H5S_hyper_mread_opt (const void *_buf, size_t elmt_size, fast_dim_offset=fast_dim_start+mem_space->select.offset[fast_dim]; /* Compute the number of blocks which would fit into the buffer */ - tot_blk_count=(size_t)io_left/(size_t)fast_dim_block; + H5_ASSIGN_OVERFLOW(tot_blk_count,(io_left/fast_dim_block),hsize_t,size_t); /* Compute the amount to wrap at the end of each row */ for(i=0; ihyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride!=0 || ((mem_iter->hyp.off[fast_dim]!=mem_space->select.sel_info.hslab.diminfo[fast_dim].start) && mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1)) { - size_t leftover; /* The number of elements left over from the last sequence */ + hsize_t leftover; /* The number of elements left over from the last sequence */ /* Calculate the number of elements left in the sequence */ if(mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1) - leftover=(size_t)mem_space->select.sel_info.hslab.diminfo[fast_dim].block - -(size_t)(mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start); + leftover=mem_space->select.sel_info.hslab.diminfo[fast_dim].block-(mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start); else - leftover=(size_t)mem_space->select.sel_info.hslab.diminfo[fast_dim].block - -(size_t)((mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride); + leftover=mem_space->select.sel_info.hslab.diminfo[fast_dim].block-((mem_iter->hyp.off[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride); /* Make certain that we don't write too many */ - actual_write=MIN(leftover,io_left); + H5_CHECK_OVERFLOW(leftover,hsize_t,size_t); + actual_write=MIN((size_t)leftover,io_left); actual_bytes=actual_write*elmt_size; /* Copy the location of the point to get */ @@ -3777,7 +3777,7 @@ H5S_hyper_mwrite_opt (const void *_tconv_buf, size_t elmt_size, fast_dim_offset=fast_dim_start+mem_space->select.offset[fast_dim]; /* Compute the number of blocks which would fit into the buffer */ - tot_blk_count=(size_t)io_left/(size_t)fast_dim_block; + H5_ASSIGN_OVERFLOW(tot_blk_count,(io_left/fast_dim_block),hsize_t,size_t); /* Compute the amount to wrap at the end of each row */ for(i=0; iextent.u.simple.rank*(size_t)block_count; + H5_CHECK_OVERFLOW((8*space->extent.u.simple.rank*block_count),hssize_t,size_t); + len+=(size_t)(8*space->extent.u.simple.rank*block_count); /* Encode each hyperslab in selection */ H5S_hyper_select_serialize_helper(space->select.sel_info.hslab.span_lst,start,end,(hsize_t)0,&buf); diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 042c6c1..3fac495 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -368,7 +368,7 @@ herr_t H5T_vlen_str_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data"); } /* end else */ - len=(size_t)seq_len*(size_t)base_size; + H5_ASSIGN_OVERFLOW(len,(seq_len*base_size),hsize_t,size_t); HDmemcpy(*s,buf,len); (*s)[len]='\0'; -- cgit v0.12