diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2001-11-27 16:29:13 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2001-11-27 16:29:13 (GMT) |
commit | d456c2bb82be98bc2b7c1039927eb52258d1a0eb (patch) | |
tree | a7d8a65aef5d962c89b0965c86eb535917c023ad /src/H5Oefl.c | |
parent | 05264c88788f9bd9b04a58673ded246904210235 (diff) | |
download | hdf5-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/H5Oefl.c')
-rw-r--r-- | src/H5Oefl.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/H5Oefl.c b/src/H5Oefl.c index 26cb732..451efbe 100644 --- a/src/H5Oefl.c +++ b/src/H5Oefl.c @@ -407,7 +407,12 @@ H5O_efl_read (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, size_t size, uint8_t *buf) { int i, fd=-1; - size_t to_read, cur, skip=0; + size_t to_read; +#ifndef NDEBUG + hsize_t tempto_read; +#endif /* NDEBUG */ + hsize_t skip; + haddr_t cur; ssize_t n; herr_t ret_value = FAIL; @@ -422,11 +427,11 @@ H5O_efl_read (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, /* Find the first efl member from which to read */ for (i=0, cur=0; i<efl->nused; i++) { if (H5O_EFL_UNLIMITED==efl->slot[i].size || - addr < cur+efl->slot[i].size) { + addr < cur+efl->slot[i].size) { skip = addr - cur; break; } - cur += efl->slot[i].size; + cur += efl->slot[i].size; } /* Read the data */ @@ -435,7 +440,7 @@ H5O_efl_read (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "read past logical end of file"); } - if (H5F_OVERFLOW_SIZET2OFFT (efl->slot[i].offset+skip)) { + if (H5F_OVERFLOW_HSIZET2OFFT (efl->slot[i].offset+skip)) { HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed"); } @@ -447,7 +452,13 @@ H5O_efl_read (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, HGOTO_ERROR (H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file"); } - to_read = MIN(efl->slot[i].size-skip, size); +#ifndef NDEBUG + tempto_read = MIN(efl->slot[i].size-skip,(hsize_t)size); + H5_CHECK_OVERFLOW(tempto_read,hsize_t,size_t); + to_read = (size_t)tempto_read; +#else /* NDEBUG */ + to_read = MIN((size_t)(efl->slot[i].size-skip), size); +#endif /* NDEBUG */ if ((n=HDread (fd, buf, to_read))<0) { HGOTO_ERROR (H5E_EFL, H5E_READERROR, FAIL, "read error in external raw data file"); @@ -492,7 +503,12 @@ H5O_efl_write (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, size_t size, const uint8_t *buf) { int i, fd=-1; - size_t to_write, cur, skip=0; + size_t to_write; +#ifndef NDEBUG + hsize_t tempto_write; +#endif /* NDEBUG */ + haddr_t cur; + hsize_t skip; herr_t ret_value = FAIL; FUNC_ENTER (H5O_efl_write, FAIL); @@ -506,7 +522,7 @@ H5O_efl_write (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, /* Find the first efl member in which to write */ for (i=0, cur=0; i<efl->nused; i++) { if (H5O_EFL_UNLIMITED==efl->slot[i].size || - addr < cur+efl->slot[i].size) { + addr < cur+efl->slot[i].size) { skip = addr - cur; break; } @@ -519,7 +535,7 @@ H5O_efl_write (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "write past logical end of file"); } - if (H5F_OVERFLOW_SIZET2OFFT (efl->slot[i].offset+skip)) { + if (H5F_OVERFLOW_HSIZET2OFFT (efl->slot[i].offset+skip)) { HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed"); } @@ -536,7 +552,13 @@ H5O_efl_write (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr, HGOTO_ERROR (H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file"); } - to_write = MIN(efl->slot[i].size-skip, size); +#ifndef NDEBUG + tempto_write = MIN(efl->slot[i].size-skip,(hsize_t)size); + H5_CHECK_OVERFLOW(tempto_write,hsize_t,size_t); + to_write = (size_t)tempto_write; +#else /* NDEBUG */ + to_write = MIN((size_t)(efl->slot[i].size-skip), size); +#endif /* NDEBUG */ if ((size_t)HDwrite (fd, buf, to_write)!=to_write) { HGOTO_ERROR (H5E_EFL, H5E_READERROR, FAIL, "write error in external raw data file"); |