summaryrefslogtreecommitdiffstats
path: root/src/H5Sall.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2001-11-27 16:29:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2001-11-27 16:29:13 (GMT)
commitd456c2bb82be98bc2b7c1039927eb52258d1a0eb (patch)
treea7d8a65aef5d962c89b0965c86eb535917c023ad /src/H5Sall.c
parent05264c88788f9bd9b04a58673ded246904210235 (diff)
downloadhdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.zip
hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.tar.gz
hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.tar.bz2
[svn-r4643] Purpose:
Code cleanup Description: Windows is generating hundreds of warnings from some of the practices in the library. Mostly, they are because size_t is 32-bit and hsize_t is 64-bit on Windows and we were carelessly casting the larger values down to the smaller ones without checking for overflow. Also, some other small code cleanups,etc. Solution: Re-worked some algorithms to eliminate the casts and also added more overflow checking for assignments and function parameters which needed casts. Kent did most of the work, I just went over his changes and fit them into the the library code a bit better. Platforms tested: FreeBSD 4.4 (hawkwind)
Diffstat (limited to 'src/H5Sall.c')
-rw-r--r--src/H5Sall.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/H5Sall.c b/src/H5Sall.c
index 0e896d9..99349cc 100644
--- a/src/H5Sall.c
+++ b/src/H5Sall.c
@@ -165,7 +165,7 @@ H5S_all_fgath (H5F_t *f, const struct H5O_layout_t *layout,
H5S_sel_iter_t *file_iter, hsize_t nelmts, hid_t dxpl_id,
void *buf/*out*/)
{
- size_t actual_bytes; /* The actual number of bytes to read */
+ hsize_t actual_bytes; /* The actual number of bytes to read */
hsize_t buf_off; /* Dataset offset for copying memory */
FUNC_ENTER (H5S_all_fgath, 0);
@@ -186,8 +186,9 @@ H5S_all_fgath (H5F_t *f, const struct H5O_layout_t *layout,
/*
* Read piece from file.
*/
+ H5_CHECK_OVERFLOW(actual_bytes,hsize_t,size_t);
if (H5F_seq_read(f, dxpl_id, layout, pline, fill, efl, file_space,
- elmt_size, actual_bytes, buf_off, buf/*out*/)<0) {
+ elmt_size, (size_t)actual_bytes, buf_off, buf/*out*/)<0) {
HRETURN_ERROR(H5E_DATASPACE, H5E_READERROR, 0, "read error");
}
@@ -226,7 +227,7 @@ H5S_all_fscat (H5F_t *f, const struct H5O_layout_t *layout,
const H5S_t *file_space, H5S_sel_iter_t *file_iter,
hsize_t nelmts, hid_t dxpl_id, const void *buf)
{
- size_t actual_bytes; /* The actual number of bytes to write */
+ hsize_t actual_bytes; /* The actual number of bytes to write */
hsize_t buf_off; /* Dataset offset for copying memory */
FUNC_ENTER (H5S_all_fscat, FAIL);
@@ -247,8 +248,9 @@ H5S_all_fscat (H5F_t *f, const struct H5O_layout_t *layout,
/*
* Write piece from file.
*/
+ H5_CHECK_OVERFLOW(actual_bytes,hsize_t,size_t);
if (H5F_seq_write(f, dxpl_id, layout, pline, fill, efl, file_space,
- elmt_size, actual_bytes, buf_off, buf/*out*/)<0) {
+ elmt_size, (size_t)actual_bytes, buf_off, buf/*out*/)<0) {
HRETURN_ERROR(H5E_DATASPACE, H5E_WRITEERROR, 0, "write error");
}
@@ -286,7 +288,7 @@ H5S_all_mgath (const void *_buf, size_t elmt_size,
hsize_t nelmts, void *tconv_buf/*out*/)
{
const uint8_t *buf=(const uint8_t*)_buf; /* Get local copies for address arithmetic */
- size_t actual_bytes; /* The actual number of bytes to read */
+ hsize_t actual_bytes; /* The actual number of bytes to read */
FUNC_ENTER (H5S_all_mgath, 0);
@@ -303,7 +305,8 @@ H5S_all_mgath (const void *_buf, size_t elmt_size,
actual_bytes=elmt_size*nelmts;
/* "read" in the bytes from the source (buf) to the destination (tconv_buf) */
- HDmemcpy(tconv_buf,buf,actual_bytes);
+ H5_CHECK_OVERFLOW(actual_bytes,hsize_t,size_t);
+ HDmemcpy(tconv_buf,buf,(size_t)actual_bytes);
/* Advance iterator */
mem_iter->all.elmt_left-=nelmts;
@@ -336,7 +339,7 @@ H5S_all_mscat (const void *tconv_buf, size_t elmt_size,
hsize_t nelmts, void *_buf/*out*/)
{
uint8_t *buf=(uint8_t *)_buf;
- size_t actual_bytes; /* The actual number of bytes to write */
+ hsize_t actual_bytes; /* The actual number of bytes to write */
FUNC_ENTER (H5S_all_mscat, FAIL);
@@ -353,7 +356,8 @@ H5S_all_mscat (const void *tconv_buf, size_t elmt_size,
actual_bytes=elmt_size*nelmts;
/* "write" the bytes from the source (tconv_buf) to the destination (buf) */
- HDmemcpy(buf,tconv_buf,actual_bytes);
+ H5_CHECK_OVERFLOW(actual_bytes,hsize_t,size_t);
+ HDmemcpy(buf,tconv_buf,(size_t)actual_bytes);
/* Advance iterator */
mem_iter->all.elmt_left-=nelmts;
@@ -406,7 +410,7 @@ H5S_all_read(H5F_t *f, const H5O_layout_t *layout, const H5O_pline_t *pline,
large_contiguous=0;
int i;
size_t down_size[H5O_LAYOUT_NDIMS];
- size_t acc;
+ hsize_t acc;
FUNC_ENTER(H5S_all_read, FAIL);
*must_convert = TRUE;
@@ -592,7 +596,7 @@ printf("%s: check 1.0\n",FUNC);
if(small_contiguous || large_contiguous) {
/* Compute the "down sizes" for each dimension */
for (acc=elmt_size, i=(mem_space->extent.u.simple.rank-1); i>=0; i--) {
- down_size[i]=acc;
+ H5_ASSIGN_OVERFLOW(down_size[i],acc,hsize_t,size_t);
acc*=mem_space->extent.u.simple.size[i];
} /* end for */
@@ -674,7 +678,7 @@ H5S_all_write(H5F_t *f, const struct H5O_layout_t *layout,
large_contiguous=0;
int i;
size_t down_size[H5O_LAYOUT_NDIMS];
- size_t acc;
+ hsize_t acc;
FUNC_ENTER(H5S_all_write, FAIL);
*must_convert = TRUE;
@@ -857,7 +861,7 @@ H5S_all_write(H5F_t *f, const struct H5O_layout_t *layout,
if(small_contiguous || large_contiguous) {
/* Compute the "down sizes" for each dimension */
for (acc=elmt_size, i=(mem_space->extent.u.simple.rank-1); i>=0; i--) {
- down_size[i]=acc;
+ H5_ASSIGN_OVERFLOW(down_size[i],acc,hsize_t,size_t);
acc*=mem_space->extent.u.simple.size[i];
} /* end for */