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/H5FDcore.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/H5FDcore.c')
-rw-r--r-- | src/H5FDcore.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 6986a74..206f5e6 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -382,7 +382,7 @@ H5FD_core_flush(H5FD_t *_file) while (size) { ssize_t n; - assert(size==(hsize_t)((size_t)size)); /*check for overflow*/ + H5_CHECK_OVERFLOW(size,hsize_t,size_t); n = HDwrite(file->fd, ptr, (size_t)size); if (n<0 && EINTR==errno) continue; if (n<0) @@ -613,7 +613,16 @@ H5FD_core_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd /* Read the part which is before the EOF marker */ if (addr < file->eof) { - size_t nbytes = MIN(size, file->eof-addr); + size_t nbytes; +#ifndef NDEBUG + hsize_t temp_nbytes; + + temp_nbytes = file->eof-addr; + H5_CHECK_OVERFLOW(temp_nbytes,hsize_t,size_t); + nbytes = MIN(size,(size_t)temp_nbytes); +#else /* NDEBUG */ + nbytes = MIN(size,(size_t)(file->eof-addr)); +#endif /* NDEBUG */ HDmemcpy(buf, file->mem + addr, nbytes); size -= nbytes; @@ -673,7 +682,9 @@ H5FD_core_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had */ if (addr+size>file->eof) { unsigned char *x; - size_t new_eof = file->increment * ((addr+size)/file->increment); + size_t new_eof; + + H5_ASSIGN_OVERFLOW(new_eof,file->increment*((addr+size)/file->increment),hsize_t,size_t); if ((addr+size) % file->increment) new_eof += file->increment; |