summaryrefslogtreecommitdiffstats
path: root/src/H5FD.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/H5FD.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/H5FD.c')
-rw-r--r--src/H5FD.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/H5FD.c b/src/H5FD.c
index c2f893f..9262323 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -2035,7 +2035,10 @@ H5FD_read(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t siz
unsigned char *read_buf=(unsigned char *)buf; /* Pointer to the buffer being read in */
size_t amount_read; /* Amount to read at a time */
- haddr_t read_off; /* Offset to read from */
+#ifndef NDEBUG
+ hsize_t tempamount_read; /* Amount to read at a time */
+#endif /* NDEBUG */
+ hsize_t read_off; /* Offset to read from */
/* Double check that we aren't reading raw data */
assert(type!=H5FD_MEM_DRAW);
@@ -2043,7 +2046,7 @@ H5FD_read(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t siz
/* Read the part before the metadata accumulator */
if(addr<file->accum_loc) {
/* Set the amount to read */
- amount_read=file->accum_loc-addr;
+ H5_ASSIGN_OVERFLOW(amount_read,file->accum_loc-addr,hsize_t,size_t);
/* Dispatch to driver */
if ((file->cls->read)(file, type, dxpl_id, addr, amount_read, read_buf)<0)
@@ -2061,7 +2064,13 @@ H5FD_read(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t siz
read_off=addr-file->accum_loc;
/* Set the amount to "read" */
- amount_read=MIN((file->accum_size-read_off),size);
+#ifndef NDEBUG
+ tempamount_read = file->accum_size-read_off;
+ H5_CHECK_OVERFLOW(tempamount_read,hsize_t,size_t);
+ amount_read = MIN(size, (size_t)tempamount_read);
+#else /* NDEBUG */
+ amount_read = MIN(size, (size_t)tempamount_read);
+#endif /* NDEBUG */
/* Copy the data out of the buffer */
HDmemcpy(read_buf,file->meta_accum+read_off,amount_read);
@@ -2249,7 +2258,7 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si
/* Check if the new metadata overlaps the beginning of the current accumulator */
else if(addr<file->accum_loc && (addr+size)<=(file->accum_loc+file->accum_size)) {
/* Calculate the new accumulator size, based on the amount of overlap */
- new_size=(file->accum_loc-addr)+file->accum_size;
+ H5_ASSIGN_OVERFLOW(new_size,(file->accum_loc-addr)+file->accum_size,hsize_t,size_t);
/* Check if we need more buffer space */
if(new_size>file->accum_buf_size) {
@@ -2262,7 +2271,7 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si
} /* end if */
/* Calculate the proper offset of the existing metadata */
- old_offset=(addr+size)-file->accum_loc;
+ H5_ASSIGN_OVERFLOW(old_offset,(addr+size)-file->accum_loc,hsize_t,size_t);
/* Move the existing metadata to the proper location */
HDmemmove(file->meta_accum+size,file->meta_accum+old_offset,(file->accum_size-old_offset));
@@ -2280,7 +2289,7 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si
/* Check if the new metadata overlaps the end of the current accumulator */
else if(addr>=file->accum_loc && (addr+size)>(file->accum_loc+file->accum_size)) {
/* Calculate the new accumulator size, based on the amount of overlap */
- new_size=(addr-file->accum_loc)+size;
+ H5_ASSIGN_OVERFLOW(new_size,(addr-file->accum_loc)+size,hsize_t,size_t);
/* Check if we need more buffer space */
if(new_size>file->accum_buf_size) {