summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMuQun Yang <ymuqun@hdfgroup.org>2002-05-02 18:56:32 (GMT)
committerMuQun Yang <ymuqun@hdfgroup.org>2002-05-02 18:56:32 (GMT)
commit84d5daad4faa490f541aa87aa2b8ce8dd047cfce (patch)
treecf90fe5db2f277c54503554281d43240621c89ae /src
parent5979d5776fe92998fe07768aa070c76f75459324 (diff)
downloadhdf5-84d5daad4faa490f541aa87aa2b8ce8dd047cfce.zip
hdf5-84d5daad4faa490f541aa87aa2b8ce8dd047cfce.tar.gz
hdf5-84d5daad4faa490f541aa87aa2b8ce8dd047cfce.tar.bz2
[svn-r5326]
Purpose: code clean-up Description: Many warnings are generated on windows due to seemingly large-size data type converting to small-size data type, 1.5 branch has been cleaned up, make 1.4 catch up with 1.5. Solution: If meeting with the break-up of the current tests on other platforms, will resume the previous one Platforms tested: windows 2000, linux 2.2.18
Diffstat (limited to 'src')
-rw-r--r--src/H5A.c34
-rw-r--r--src/H5B.c6
-rw-r--r--src/H5Distore.c41
-rw-r--r--src/H5FD.c16
-rw-r--r--src/H5FDcore.c23
-rw-r--r--src/H5FDfamily.c29
-rw-r--r--src/H5FDlog.c2
-rw-r--r--src/H5Farray.c9
-rw-r--r--src/H5Fistore.c41
-rw-r--r--src/H5Fpkg.h8
-rw-r--r--src/H5O.c1
-rw-r--r--src/H5Oefl.c31
-rw-r--r--src/H5P.c2
-rw-r--r--src/H5R.c10
-rw-r--r--src/H5Sall.c22
-rw-r--r--src/H5Smpio.c2
-rw-r--r--src/H5T.c11
-rw-r--r--src/H5TB.c14
-rw-r--r--src/H5Tvlen.c20
-rw-r--r--src/H5V.c3
-rw-r--r--src/H5private.h17
21 files changed, 223 insertions, 119 deletions
diff --git a/src/H5A.c b/src/H5A.c
index f7c859d..f88a267 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -253,7 +253,8 @@ H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type,
/* Compute the internal sizes */
attr->dt_size=(H5O_DTYPE[0].raw_size)(attr->ent.file,type);
attr->ds_size=(H5O_SDSPACE[0].raw_size)(attr->ent.file,&(space->extent.u.simple));
- attr->data_size=H5S_get_simple_extent_npoints(attr->ds)*H5T_get_size(attr->dt);
+
+ H5_ASSIGN_OVERFLOW(attr->data_size,H5S_get_simple_extent_npoints(space)*H5T_get_size(attr->dt),hssize_t,size_t);
/* Hold the symbol table entry (and file) open */
if (H5O_open(&(attr->ent)) < 0) {
@@ -618,7 +619,7 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf)
hid_t src_id = -1, dst_id = -1;/* temporary type atoms */
size_t src_type_size; /* size of source type */
size_t dst_type_size; /* size of destination type*/
- hsize_t buf_size; /* desired buffer size */
+ size_t buf_size; /* desired buffer size */
int idx; /* index of attribute in object header */
herr_t ret_value = FAIL;
@@ -636,16 +637,14 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf)
dst_type_size = H5T_get_size(attr->dt);
/* Get the maximum buffer size needed and allocate it */
- buf_size = nelmts*MAX(src_type_size,dst_type_size);
- assert(buf_size==(hsize_t)((size_t)buf_size)); /*check for overflow*/
- if (NULL==(tconv_buf = H5MM_malloc ((size_t)buf_size)) ||
- NULL==(bkg_buf = H5MM_calloc((size_t)buf_size))) {
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
+
+ H5_ASSIGN_OVERFLOW(buf_size,nelmts*MAX(src_type_size,dst_type_size),hsize_t,size_t);
+ if (NULL==(tconv_buf = H5MM_malloc (buf_size)) || NULL==(bkg_buf = H5MM_calloc(buf_size)))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+
/* Copy the user's data into the buffer for conversion */
- assert((src_type_size*nelmts)==(hsize_t)((size_t)(src_type_size*nelmts))); /*check for overflow*/
+ H5_CHECK_OVERFLOW((src_type_size*nelmts),hsize_t,size_t);
HDmemcpy(tconv_buf,buf,(size_t)(src_type_size*nelmts));
/* Convert memory buffer into disk buffer */
@@ -781,7 +780,7 @@ H5A_read(H5A_t *attr, const H5T_t *mem_type, void *buf)
hid_t src_id = -1, dst_id = -1;/* temporary type atoms*/
size_t src_type_size; /* size of source type */
size_t dst_type_size; /* size of destination type */
- hsize_t buf_size; /* desired buffer size */
+ size_t buf_size; /* desired buffer size */
herr_t ret_value = FAIL;
FUNC_ENTER(H5A_read, FAIL);
@@ -798,19 +797,16 @@ H5A_read(H5A_t *attr, const H5T_t *mem_type, void *buf)
dst_type_size = H5T_get_size(mem_type);
/* Check if the attribute has any data yet, if not, fill with zeroes */
- assert((dst_type_size*nelmts)==(hsize_t)((size_t)(dst_type_size*nelmts))); /*check for overflow*/
+ H5_CHECK_OVERFLOW((dst_type_size*nelmts),hsize_t,size_t);
+
if(attr->ent_opened && !attr->initialized) {
HDmemset(buf,0,(size_t)(dst_type_size*nelmts));
} /* end if */
else { /* Attribute exists and has a value */
/* Get the maximum buffer size needed and allocate it */
- buf_size = nelmts*MAX(src_type_size,dst_type_size);
- assert(buf_size==(hsize_t)((size_t)buf_size)); /*check for overflow*/
- if (NULL==(tconv_buf = H5MM_malloc ((size_t)buf_size)) ||
- NULL==(bkg_buf = H5MM_calloc((size_t)buf_size))) {
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
+ H5_ASSIGN_OVERFLOW(buf_size,(nelmts*MAX(src_type_size,dst_type_size)),hsize_t,size_t);
+ if (NULL==(tconv_buf = H5MM_malloc (buf_size)) || NULL==(bkg_buf = H5MM_calloc(buf_size)))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
/* Copy the attribute data into the buffer for conversion */
assert((src_type_size*nelmts)==(hsize_t)((size_t)(src_type_size*nelmts))); /*check for overflow*/
diff --git a/src/H5B.c b/src/H5B.c
index 2bd1a0f..c2fe735 100644
--- a/src/H5B.c
+++ b/src/H5B.c
@@ -680,11 +680,11 @@ H5B_split(H5F_t *f, const H5B_class_t *type, H5B_t *old_bt, haddr_t old_addr,
* and the new node.
*/
if (!H5F_addr_defined(old_bt->right)) {
- nleft = 2 * k * split_ratios[2]; /*right*/
+ nleft = (int)(2 * k * split_ratios[2]); /*right*/
} else if (!H5F_addr_defined(old_bt->left)) {
- nleft = 2 * k * split_ratios[0]; /*left*/
+ nleft = (int)(2 * k * split_ratios[0]); /*left*/
} else {
- nleft = 2 * k * split_ratios[1]; /*middle*/
+ nleft = (int)(2 * k * split_ratios[1]); /*middle*/
}
/*
diff --git a/src/H5Distore.c b/src/H5Distore.c
index e76432b..f78ae86 100644
--- a/src/H5Distore.c
+++ b/src/H5Distore.c
@@ -1230,7 +1230,7 @@ H5F_istore_prune (H5F_t *f, size_t size)
* begins. The pointers participating in the list traversal are each
* given a chance at preemption before any of the pointers are advanced.
*/
- w[0] = rdcc->nused * f->shared->rdcc_w0;
+ w[0] = (int)(rdcc->nused * f->shared->rdcc_w0);
p[0] = rdcc->head;
p[1] = NULL;
@@ -1336,13 +1336,14 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
int *idx_hint/*in,out*/)
{
int idx=0; /*hash index number */
- unsigned temp_idx=0; /* temporary index number */
+ hsize_t temp_idx=0; /* temporary index number */
hbool_t found = FALSE; /*already in cache? */
H5F_rdcc_t *rdcc = &(f->shared->rdcc);/*raw data chunk cache*/
H5F_rdcc_ent_t *ent = NULL; /*cache entry */
unsigned u; /*counters */
H5F_istore_ud1_t udata; /*B-tree pass-through */
size_t chunk_size=0; /*size of a chunk */
+ hsize_t tempchunk_size;
size_t chunk_alloc=0; /*allocated chunk size */
herr_t status; /*func return status */
void *chunk=NULL; /*the file chunk */
@@ -1356,7 +1357,7 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
temp_idx *= layout->dim[u];
temp_idx += offset[u];
}
- temp_idx += (unsigned)(layout->addr);
+ temp_idx += (hsize_t)(layout->addr);
idx=H5F_HASH(f,temp_idx);
ent = rdcc->slot[idx];
@@ -1389,9 +1390,10 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
fflush(stderr);
#endif
rdcc->nhits++;
- for (u=0, chunk_size=1; u<layout->ndims; u++) {
- chunk_size *= layout->dim[u];
+ for (u=0, tempchunk_size=1; u<layout->ndims; u++) {
+ tempchunk_size *= layout->dim[u];
}
+ H5_ASSIGN_OVERFLOW(chunk_size,tempchunk_size,hsize_t,size_t);
chunk_alloc = chunk_size;
if (NULL==(chunk=H5F_istore_chunk_alloc (chunk_alloc))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
@@ -1403,10 +1405,11 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
* Not in the cache. Read it from the file and count this as a miss
* if it's in the file or an init if it isn't.
*/
- for (u=0, chunk_size=1; u<layout->ndims; u++) {
+ for (u=0, tempchunk_size=1; u<layout->ndims; u++) {
udata.key.offset[u] = offset[u];
- chunk_size *= layout->dim[u];
+ tempchunk_size *= layout->dim[u];
}
+ H5_ASSIGN_OVERFLOW(chunk_size,tempchunk_size,hsize_t,size_t);
chunk_alloc = chunk_size;
udata.mesg = *layout;
udata.addr = HADDR_UNDEF;
@@ -1634,15 +1637,16 @@ H5F_istore_unlock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
*/
if (dirty) {
H5F_rdcc_ent_t x;
-
+ hsize_t tempchunk_size;
HDmemset (&x, 0, sizeof x);
x.dirty = TRUE;
x.layout = H5O_copy (H5O_LAYOUT, layout, NULL);
x.pline = H5O_copy (H5O_PLINE, pline, NULL);
- for (u=0, x.chunk_size=1; u<layout->ndims; u++) {
+ for (u=0, tempchunk_size=1; u<layout->ndims; u++) {
x.offset[u] = offset[u];
- x.chunk_size *= layout->dim[u];
+ tempchunk_size *= layout->dim[u];
}
+ H5_ASSIGN_OVERFLOW(x.chunk_size,tempchunk_size,hsize_t,size_t);
x.alloc_size = x.chunk_size;
x.chunk = chunk;
{
@@ -1710,7 +1714,7 @@ H5F_istore_read(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
hssize_t chunk_offset[H5O_LAYOUT_NDIMS];
int i, carry;
unsigned u;
- size_t naccessed; /*bytes accessed in chnk*/
+ hsize_t naccessed; /*bytes accessed in chnk*/
uint8_t *chunk=NULL; /*ptr to a chunk buffer */
int idx_hint=0; /*cache index hint */
hsize_t chunk_size; /* Bytes in chunk */
@@ -1833,9 +1837,10 @@ H5F_istore_read(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
}
H5V_hyper_copy(layout->ndims, sub_size, size_m, sub_offset_m,
(void*)buf, layout->dim, offset_wrt_chunk, chunk);
- if (H5F_istore_unlock(f, dxpl_id, layout, pline, FALSE,
+ H5_CHECK_OVERFLOW(naccessed,hsize_t,size_t);
+ if (H5F_istore_unlock(f, dxpl_id, layout, pline, FALSE,
chunk_offset, &idx_hint, chunk,
- naccessed)<0) {
+ (size_t)naccessed)<0) {
HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL,
"unable to unlock raw data chunk");
}
@@ -1891,7 +1896,7 @@ H5F_istore_write(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
hssize_t sub_offset_m[H5O_LAYOUT_NDIMS];
uint8_t *chunk=NULL;
int idx_hint=0;
- size_t chunk_size, naccessed;
+ hsize_t chunk_size, naccessed;
haddr_t chunk_addr; /* Chunk address on disk */
FUNC_ENTER(H5F_istore_write, FAIL);
@@ -2015,9 +2020,10 @@ H5F_istore_write(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
}
H5V_hyper_copy(layout->ndims, sub_size,
layout->dim, offset_wrt_chunk, chunk, size_m, sub_offset_m, buf);
+ H5_CHECK_OVERFLOW(naccessed,hsize_t,size_t);
if (H5F_istore_unlock(f, dxpl_id, layout, pline, TRUE,
chunk_offset, &idx_hint, chunk,
- naccessed)<0) {
+ (size_t)naccessed)<0) {
HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL,
"uanble to unlock raw data chunk");
}
@@ -2347,7 +2353,7 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
hssize_t chunk_offset[H5O_LAYOUT_NDIMS];
uint8_t *chunk=NULL;
int idx_hint=0;
- size_t chunk_size;
+ hsize_t chunk_size;
#ifdef AKC
H5F_istore_ud1_t udata;
#endif
@@ -2412,8 +2418,9 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL,
"unable to read raw data chunk");
}
+ H5_CHECK_OVERFLOW(chunk_size,hsize_t,size_t);
if (H5F_istore_unlock(f, dxpl_id, layout, pline, TRUE,
- chunk_offset, &idx_hint, chunk, chunk_size)<0) {
+ chunk_offset, &idx_hint, chunk, (size_t)chunk_size)<0) {
HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL,
"uanble to unlock raw data chunk");
}
diff --git a/src/H5FD.c b/src/H5FD.c
index 29c1498..1554f5c 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -2127,7 +2127,7 @@ H5FD_read(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t si
/* 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)
@@ -2148,7 +2148,9 @@ H5FD_read(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t si
amount_read=MIN((file->accum_size-read_off),size);
/* Copy the data out of the buffer */
- assert(amount_read==(hsize_t)((size_t)amount_read)); /*check for overflow*/
+ H5_CHECK_OVERFLOW(amount_read,hsize_t,size_t);
+ /* assert(amount_read==(hsize_t)((size_t)amount_read)); *//*check for overflow*/
+
HDmemcpy(read_buf,file->meta_accum+read_off,(size_t)amount_read);
/* Adjust the buffer, address & size */
@@ -2342,8 +2344,7 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t s
/* 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) {
/* Reallocate the metadata accumulator buffer */
@@ -2358,11 +2359,11 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t s
old_offset=(addr+size)-file->accum_loc;
/* Move the existing metadata to the proper location */
- assert((file->accum_size-old_offset)==(hsize_t)((size_t)(file->accum_size-old_offset))); /*check for overflow*/
+ H5_ASSIGN_OVERFLOW(old_offset,(addr+size)-file->accum_loc,hsize_t,size_t);/*check for overflow*/
HDmemmove(file->meta_accum+size,file->meta_accum+old_offset,(size_t)(file->accum_size-old_offset));
/* Copy the new metadata at the front */
- assert(size==(hsize_t)((size_t)size)); /*check for overflow*/
+ H5_CHECK_OVERFLOW(size,hsize_t,size_t); /*check for overflow*/
HDmemcpy(file->meta_accum,buf,(size_t)size);
/* Set the new size & location of the metadata accumulator */
@@ -2375,8 +2376,7 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t s
/* 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) {
/* Reallocate the metadata accumulator buffer */
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index 909275c..15bb866 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -365,7 +365,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);/*check for overflow*/
n = HDwrite(file->fd, ptr, (size_t)size);
if (n<0 && EINTR==errno) continue;
if (n<0)
@@ -596,10 +596,19 @@ 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) {
- hsize_t nbytes = MIN(size, file->eof-addr);
-
- assert(nbytes==(hsize_t)((size_t)nbytes)); /*check for overflow*/
- HDmemcpy(buf, file->mem + addr, (size_t)nbytes);
+ 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;
addr += nbytes;
buf = (char *)buf + nbytes;
@@ -658,8 +667,10 @@ 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;
if (NULL==file->mem) x = H5MM_malloc(new_eof);
else x = H5MM_realloc(file->mem, new_eof);
diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c
index 79d7c8a..12a102c 100644
--- a/src/H5FDfamily.c
+++ b/src/H5FDfamily.c
@@ -821,6 +821,9 @@ H5FD_family_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hs
int i;
haddr_t sub;
hsize_t req;
+#ifndef NDEBUG
+ hsize_t tempreq;
+#endif /* NDEBUG */
FUNC_ENTER(H5FD_family_read, FAIL);
@@ -838,9 +841,16 @@ H5FD_family_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hs
/* Read from each member */
while (size>0) {
- i = addr / file->memb_size;
+ H5_ASSIGN_OVERFLOW(i,addr /file->memb_size,hsize_t,int);
sub = addr % file->memb_size;
- req = MIN(size, file->memb_size-sub);
+#ifndef NDEBUG
+ tempreq = file->memb_size-sub;
+ H5_CHECK_OVERFLOW(tempreq,hsize_t,size_t);
+ req = MIN(size, (size_t)tempreq);
+#else /* NDEBUG */
+ req = MIN(size, (size_t)(file->memb_size-sub));
+#endif /* NDEBUG */
+
assert(i<file->nmembs);
if (H5FDread(file->memb[i], type, memb_dxpl_id, sub, req, buf)<0)
@@ -884,6 +894,9 @@ H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, h
int i;
haddr_t sub;
hsize_t req;
+#ifndef NDEBUG
+ hsize_t tempreq;
+#endif /* NDEBUG */
FUNC_ENTER(H5FD_family_write, FAIL);
@@ -901,9 +914,17 @@ H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, h
/* Write to each member */
while (size>0) {
- i = addr / file->memb_size;
+
+ H5_ASSIGN_OVERFLOW(i,addr /file->memb_size,hsize_t,int);
sub = addr % file->memb_size;
- req = MIN(size, file->memb_size-sub);
+#ifndef NDEBUG
+ tempreq = file->memb_size-sub;
+ H5_CHECK_OVERFLOW(tempreq,hsize_t,size_t);
+ req = MIN(size, (size_t)tempreq);
+#else /* NDEBUG */
+ req = MIN(size, (size_t)(file->memb_size-sub));
+#endif /* NDEBUG */
+
assert(i<file->nmembs);
if (H5FDwrite(file->memb[i], type, memb_dxpl_id, sub, req, buf)<0)
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index f42c5f7..f5293e0 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -696,7 +696,7 @@ printf("%s: flavor=%s, size=%lu\n",FUNC,flavors[type],(unsigned long)size);
/* Retain the (first) flavor of the information written to the file */
if(file->fa.verbosity>=0) {
assert(addr<file->iosize);
- assert(size==(hsize_t)((size_t)size)); /*check for overflow*/
+ H5_CHECK_OVERFLOW(size,hsize_t,size_t);
HDmemset(&file->flavor[addr],type,(size_t)size);
if(file->fa.verbosity>1)
diff --git a/src/H5Farray.c b/src/H5Farray.c
index 7a4f10c..f0e9298 100644
--- a/src/H5Farray.c
+++ b/src/H5Farray.c
@@ -142,7 +142,7 @@ H5F_arr_read(H5F_t *f, hid_t dxpl_id, const struct H5O_layout_t *layout,
hsize_t file_start; /*byte offset to start */
hsize_t max_data = 0; /*bytes in dataset */
hsize_t elmt_size = 1; /*bytes per element */
- size_t nelmts, z; /*number of elements */
+ hsize_t nelmts, z; /*number of elements */
unsigned ndims; /*stride dimensionality */
haddr_t addr; /*address in file */
int j; /*counters */
@@ -229,9 +229,8 @@ H5F_arr_read(H5F_t *f, hid_t dxpl_id, const struct H5O_layout_t *layout,
* and memory. Optimize the strides to result in the fewest number of
* I/O requests.
*/
- mem_start = H5V_hyper_stride(ndims, hslab_size, mem_size,
- mem_offset, mem_stride/*out*/);
- file_start = H5V_hyper_stride(ndims, hslab_size, layout->dim,
+ H5_ASSIGN_OVERFLOW(mem_start,H5V_hyper_stride(ndims, hslab_size, mem_size, mem_offset, mem_stride/*out*/),hsize_t,size_t);
+ file_start = H5V_hyper_stride(ndims, hslab_size, layout->dim,
file_offset, file_stride/*out*/);
H5V_stride_optimize2(&ndims, &elmt_size, hslab_size,
mem_stride, file_stride);
@@ -424,7 +423,7 @@ H5F_arr_write(H5F_t *f, hid_t dxpl_id, const struct H5O_layout_t *layout,
hsize_t file_start; /*byte offset to start */
hsize_t max_data = 0; /*bytes in dataset */
hsize_t elmt_size = 1; /*bytes per element */
- size_t nelmts, z; /*number of elements */
+ hsize_t nelmts, z; /*number of elements */
unsigned ndims; /*dimensionality */
haddr_t addr; /*address in file */
int j; /*counters */
diff --git a/src/H5Fistore.c b/src/H5Fistore.c
index e76432b..f78ae86 100644
--- a/src/H5Fistore.c
+++ b/src/H5Fistore.c
@@ -1230,7 +1230,7 @@ H5F_istore_prune (H5F_t *f, size_t size)
* begins. The pointers participating in the list traversal are each
* given a chance at preemption before any of the pointers are advanced.
*/
- w[0] = rdcc->nused * f->shared->rdcc_w0;
+ w[0] = (int)(rdcc->nused * f->shared->rdcc_w0);
p[0] = rdcc->head;
p[1] = NULL;
@@ -1336,13 +1336,14 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
int *idx_hint/*in,out*/)
{
int idx=0; /*hash index number */
- unsigned temp_idx=0; /* temporary index number */
+ hsize_t temp_idx=0; /* temporary index number */
hbool_t found = FALSE; /*already in cache? */
H5F_rdcc_t *rdcc = &(f->shared->rdcc);/*raw data chunk cache*/
H5F_rdcc_ent_t *ent = NULL; /*cache entry */
unsigned u; /*counters */
H5F_istore_ud1_t udata; /*B-tree pass-through */
size_t chunk_size=0; /*size of a chunk */
+ hsize_t tempchunk_size;
size_t chunk_alloc=0; /*allocated chunk size */
herr_t status; /*func return status */
void *chunk=NULL; /*the file chunk */
@@ -1356,7 +1357,7 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
temp_idx *= layout->dim[u];
temp_idx += offset[u];
}
- temp_idx += (unsigned)(layout->addr);
+ temp_idx += (hsize_t)(layout->addr);
idx=H5F_HASH(f,temp_idx);
ent = rdcc->slot[idx];
@@ -1389,9 +1390,10 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
fflush(stderr);
#endif
rdcc->nhits++;
- for (u=0, chunk_size=1; u<layout->ndims; u++) {
- chunk_size *= layout->dim[u];
+ for (u=0, tempchunk_size=1; u<layout->ndims; u++) {
+ tempchunk_size *= layout->dim[u];
}
+ H5_ASSIGN_OVERFLOW(chunk_size,tempchunk_size,hsize_t,size_t);
chunk_alloc = chunk_size;
if (NULL==(chunk=H5F_istore_chunk_alloc (chunk_alloc))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
@@ -1403,10 +1405,11 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
* Not in the cache. Read it from the file and count this as a miss
* if it's in the file or an init if it isn't.
*/
- for (u=0, chunk_size=1; u<layout->ndims; u++) {
+ for (u=0, tempchunk_size=1; u<layout->ndims; u++) {
udata.key.offset[u] = offset[u];
- chunk_size *= layout->dim[u];
+ tempchunk_size *= layout->dim[u];
}
+ H5_ASSIGN_OVERFLOW(chunk_size,tempchunk_size,hsize_t,size_t);
chunk_alloc = chunk_size;
udata.mesg = *layout;
udata.addr = HADDR_UNDEF;
@@ -1634,15 +1637,16 @@ H5F_istore_unlock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
*/
if (dirty) {
H5F_rdcc_ent_t x;
-
+ hsize_t tempchunk_size;
HDmemset (&x, 0, sizeof x);
x.dirty = TRUE;
x.layout = H5O_copy (H5O_LAYOUT, layout, NULL);
x.pline = H5O_copy (H5O_PLINE, pline, NULL);
- for (u=0, x.chunk_size=1; u<layout->ndims; u++) {
+ for (u=0, tempchunk_size=1; u<layout->ndims; u++) {
x.offset[u] = offset[u];
- x.chunk_size *= layout->dim[u];
+ tempchunk_size *= layout->dim[u];
}
+ H5_ASSIGN_OVERFLOW(x.chunk_size,tempchunk_size,hsize_t,size_t);
x.alloc_size = x.chunk_size;
x.chunk = chunk;
{
@@ -1710,7 +1714,7 @@ H5F_istore_read(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
hssize_t chunk_offset[H5O_LAYOUT_NDIMS];
int i, carry;
unsigned u;
- size_t naccessed; /*bytes accessed in chnk*/
+ hsize_t naccessed; /*bytes accessed in chnk*/
uint8_t *chunk=NULL; /*ptr to a chunk buffer */
int idx_hint=0; /*cache index hint */
hsize_t chunk_size; /* Bytes in chunk */
@@ -1833,9 +1837,10 @@ H5F_istore_read(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
}
H5V_hyper_copy(layout->ndims, sub_size, size_m, sub_offset_m,
(void*)buf, layout->dim, offset_wrt_chunk, chunk);
- if (H5F_istore_unlock(f, dxpl_id, layout, pline, FALSE,
+ H5_CHECK_OVERFLOW(naccessed,hsize_t,size_t);
+ if (H5F_istore_unlock(f, dxpl_id, layout, pline, FALSE,
chunk_offset, &idx_hint, chunk,
- naccessed)<0) {
+ (size_t)naccessed)<0) {
HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL,
"unable to unlock raw data chunk");
}
@@ -1891,7 +1896,7 @@ H5F_istore_write(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
hssize_t sub_offset_m[H5O_LAYOUT_NDIMS];
uint8_t *chunk=NULL;
int idx_hint=0;
- size_t chunk_size, naccessed;
+ hsize_t chunk_size, naccessed;
haddr_t chunk_addr; /* Chunk address on disk */
FUNC_ENTER(H5F_istore_write, FAIL);
@@ -2015,9 +2020,10 @@ H5F_istore_write(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
}
H5V_hyper_copy(layout->ndims, sub_size,
layout->dim, offset_wrt_chunk, chunk, size_m, sub_offset_m, buf);
+ H5_CHECK_OVERFLOW(naccessed,hsize_t,size_t);
if (H5F_istore_unlock(f, dxpl_id, layout, pline, TRUE,
chunk_offset, &idx_hint, chunk,
- naccessed)<0) {
+ (size_t)naccessed)<0) {
HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL,
"uanble to unlock raw data chunk");
}
@@ -2347,7 +2353,7 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
hssize_t chunk_offset[H5O_LAYOUT_NDIMS];
uint8_t *chunk=NULL;
int idx_hint=0;
- size_t chunk_size;
+ hsize_t chunk_size;
#ifdef AKC
H5F_istore_ud1_t udata;
#endif
@@ -2412,8 +2418,9 @@ H5F_istore_allocate(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL,
"unable to read raw data chunk");
}
+ H5_CHECK_OVERFLOW(chunk_size,hsize_t,size_t);
if (H5F_istore_unlock(f, dxpl_id, layout, pline, TRUE,
- chunk_offset, &idx_hint, chunk, chunk_size)<0) {
+ chunk_offset, &idx_hint, chunk, (size_t)chunk_size)<0) {
HRETURN_ERROR (H5E_IO, H5E_WRITEERROR, FAIL,
"uanble to unlock raw data chunk");
}
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index 93363cb..964490f 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -62,6 +62,14 @@
# define H5F_OVERFLOW_SIZET2OFFT(X) 0
#endif
+#if (H5_SIZEOF_HSIZE_T >= H5_SIZEOF_OFF_T)
+# define H5F_OVERFLOW_HSIZET2OFFT(X)
+ ((hsize_t)(X)>=(hsize_t)((hsize_t)1<<(8*sizeof(off_t)-1)))
+#else
+# define H5F_OVERFLOW_HSIZET2OFFT(X) 0
+#endif
+
+
/* The raw data chunk cache */
typedef struct H5F_rdcc_t {
unsigned ninits; /* Number of chunk creations */
diff --git a/src/H5O.c b/src/H5O.c
index 5636c6c..06410f1 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -383,6 +383,7 @@ H5O_load(H5F_t *f, haddr_t addr, const void UNUSED *_udata1,
/* read fixed-lenth part of object header */
hdr_size = H5O_SIZEOF_HDR(f);
+ assert(hdr_size<=sizeof(buf));
if (H5F_block_read(f, H5FD_MEM_OHDR, addr, hdr_size, H5P_DEFAULT, buf) < 0) {
HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL,
"unable to read object header");
diff --git a/src/H5Oefl.c b/src/H5Oefl.c
index e4dd65f..9ab21e7 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,
hsize_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
+ hsize_t skip;
+ haddr_t cur;
ssize_t n;
herr_t ret_value = FAIL;
@@ -447,7 +452,14 @@ 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 +504,12 @@ H5O_efl_write (H5F_t UNUSED *f, const H5O_efl_t *efl, haddr_t addr,
hsize_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);
@@ -536,7 +553,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");
diff --git a/src/H5P.c b/src/H5P.c
index e4e3151..f71537a 100644
--- a/src/H5P.c
+++ b/src/H5P.c
@@ -1495,7 +1495,7 @@ herr_t
H5Pset_external(hid_t plist_id, const char *name, off_t offset, hsize_t size)
{
int idx;
- size_t total, tmp;
+ hsize_t total, tmp;
H5D_create_t *plist = NULL;
FUNC_ENTER(H5Pset_external, FAIL);
diff --git a/src/H5R.c b/src/H5R.c
index b936cb5..6e19ac2 100644
--- a/src/H5R.c
+++ b/src/H5R.c
@@ -200,11 +200,9 @@ H5R_create(void *_ref, H5G_entry_t *loc, const char *name, H5R_type_t ref_type,
buf_size+=sizeof(haddr_t);
/* Allocate the space to store the serialized information */
- assert(buf_size==(hssize_t)((size_t)buf_size)); /*check for overflow*/
- if (NULL==(buf = H5MM_malloc((size_t)buf_size))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
+ H5_CHECK_OVERFLOW(buf_size,hssize_t,size_t);
+ if (NULL==(buf = H5MM_malloc((size_t)buf_size)))
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
/* Serialize information for dataset OID */
p=(uint8_t *)buf;
@@ -217,7 +215,7 @@ H5R_create(void *_ref, H5G_entry_t *loc, const char *name, H5R_type_t ref_type,
"Unable to serialize selection");
/* Save the serialized buffer for later */
- assert(buf_size==(hssize_t)((size_t)buf_size)); /*check for overflow*/
+ H5_CHECK_OVERFLOW(buf_size,hssize_t,size_t);
if(H5HG_insert(loc->file,(size_t)buf_size,buf,&hobjid)<0)
HGOTO_ERROR(H5E_REFERENCE, H5E_WRITEERROR, FAIL,
"Unable to serialize selection");
diff --git a/src/H5Sall.c b/src/H5Sall.c
index 4106549..6c4f220 100644
--- a/src/H5Sall.c
+++ b/src/H5Sall.c
@@ -188,8 +188,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");
}
@@ -249,8 +250,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");
}
@@ -305,7 +307,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;
@@ -338,7 +341,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);
@@ -355,7 +358,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;
@@ -409,7 +413,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;
@@ -565,7 +569,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 */
@@ -643,7 +647,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;
@@ -796,7 +800,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 */
diff --git a/src/H5Smpio.c b/src/H5Smpio.c
index 3d2b92b..4dc6b2f 100644
--- a/src/H5Smpio.c
+++ b/src/H5Smpio.c
@@ -105,7 +105,7 @@ H5S_mpio_all_type( const H5S_t *space, const size_t elmt_size,
/* fill in the return values */
*new_type = MPI_BYTE;
- *count = total_bytes;
+ *count = (size_t)total_bytes;
*is_derived_type = 0;
#ifdef H5Smpi_DEBUG
diff --git a/src/H5T.c b/src/H5T.c
index 785737f..146c203 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -2803,8 +2803,7 @@ H5Tget_ebias(hid_t type_id)
}
/* bias */
- ebias = dt->u.atomic.u.f.ebias;
-
+ H5_ASSIGN_OVERFLOW(ebias,dt->u.atomic.u.f.ebias,uint64_t,size_t);
FUNC_LEAVE(ebias);
}
@@ -7385,7 +7384,7 @@ H5T_array_create(H5T_t *base, int ndims, const hsize_t dim[/* ndims */],
/* Copy the array dimensions & compute the # of elements in the array */
for(i=0, ret_value->u.array.nelem=1; i<ndims; i++) {
- ret_value->u.array.dim[i] = dim[i];
+ H5_ASSIGN_OVERFLOW(ret_value->u.array.dim[i],dim[i],hsize_t,size_t);
ret_value->u.array.nelem *= dim[i];
} /* end for */
@@ -7701,12 +7700,12 @@ H5T_debug(H5T_t *dt, FILE *stream)
(unsigned long) (dt->u.atomic.u.f.esize));
tmp = dt->u.atomic.u.f.ebias >> 32;
if (tmp) {
- size_t hi = tmp;
- size_t lo = dt->u.atomic.u.f.ebias & 0xffffffff;
+ size_t hi = (size_t)tmp;
+ size_t lo = (size_t)(dt->u.atomic.u.f.ebias & 0xffffffff);
fprintf(stream, " bias=0x%08lx%08lx",
(unsigned long)hi, (unsigned long)lo);
} else {
- size_t lo = dt->u.atomic.u.f.ebias & 0xffffffff;
+ size_t lo = (size_t)(dt->u.atomic.u.f.ebias & 0xffffffff);
fprintf(stream, " bias=0x%08lx", (unsigned long)lo);
}
break;
diff --git a/src/H5TB.c b/src/H5TB.c
index 9450650..016728b 100644
--- a/src/H5TB.c
+++ b/src/H5TB.c
@@ -1154,15 +1154,17 @@ H5TB_ffind(H5TB_NODE * root, void * key, unsigned fast_compare, H5TB_NODE ** pp)
H5TB_NODE *parent = NULL;
int side;
int cmp = 1;
+ haddr_t cmp_addr = 1;
+ H5TB_NODE *ret_value = NULL;
FUNC_ENTER (H5TB_ffind, NULL);
switch(fast_compare) {
case H5TB_FAST_HADDR_COMPARE:
if (ptr) {
- while (0 != (cmp = (*(haddr_t *)key - *(haddr_t *)ptr->key))) {
+ while (0 != (cmp_addr = (*(haddr_t *)key - *(haddr_t *)ptr->key))) {
parent = ptr;
- side = (cmp < 0) ? LEFT : RIGHT;
+ side = (cmp_addr < 0) ? LEFT : RIGHT;
if (!HasChild(ptr, side))
break;
ptr = ptr->link[side];
@@ -1170,6 +1172,9 @@ H5TB_ffind(H5TB_NODE * root, void * key, unsigned fast_compare, H5TB_NODE ** pp)
} /* end if */
if (NULL != pp)
*pp = parent;
+
+ /* Set return value */
+ ret_value= (0 == cmp_addr) ? ptr : NULL;
break;
case H5TB_FAST_INTN_COMPARE:
@@ -1184,13 +1189,16 @@ H5TB_ffind(H5TB_NODE * root, void * key, unsigned fast_compare, H5TB_NODE ** pp)
} /* end if */
if (NULL != pp)
*pp = parent;
+
+ /* Set return value */
+ ret_value= (0 == cmp) ? ptr : NULL;
break;
default:
break;
} /* end switch */
- FUNC_LEAVE((0 == cmp) ? ptr : NULL);
+ FUNC_LEAVE(ret_value);
} /* H5TB_ffind() */
/* swapkid -- Often refered to as "rotating" nodes. ptr and ptr's `side'
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c
index bf5a616..7491b8a 100644
--- a/src/H5Tvlen.c
+++ b/src/H5Tvlen.c
@@ -205,7 +205,8 @@ herr_t H5T_vlen_seq_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t l
herr_t H5T_vlen_seq_mem_write(const H5D_xfer_t *xfer_parms, H5F_t UNUSED *f, void *vl_addr, void *buf, hsize_t seq_len, hsize_t base_size)
{
hvl_t *vl=(hvl_t *)vl_addr; /* Pointer to the user's hvl_t information */
- size_t len=seq_len*base_size;
+ size_t len;
+ H5_ASSIGN_OVERFLOW(len,(seq_len*base_size),hsize_t,size_t);
FUNC_ENTER (H5T_vlen_seq_mem_write, FAIL);
@@ -215,13 +216,12 @@ herr_t H5T_vlen_seq_mem_write(const H5D_xfer_t *xfer_parms, H5F_t UNUSED *f, voi
if(seq_len!=0) {
/* Use the user's memory allocation routine is one is defined */
- assert((seq_len*base_size)==(hsize_t)((size_t)(seq_len*base_size))); /*check for overflow*/
if(xfer_parms->vlen_alloc!=NULL) {
- if(NULL==(vl->p=(xfer_parms->vlen_alloc)((size_t)(seq_len*base_size),xfer_parms->alloc_info)))
+ if(NULL==(vl->p=(xfer_parms->vlen_alloc)(len,xfer_parms->alloc_info)))
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data");
} /* end if */
else { /* Default to system malloc */
- if(NULL==(vl->p=H5MM_malloc((size_t)(seq_len*base_size))))
+ if(NULL==(vl->p=H5MM_malloc(len)))
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data");
} /* end else */
@@ -233,7 +233,7 @@ herr_t H5T_vlen_seq_mem_write(const H5D_xfer_t *xfer_parms, H5F_t UNUSED *f, voi
vl->p=NULL;
/* Set the sequence length */
- vl->len=seq_len;
+ H5_ASSIGN_OVERFLOW(vl->len,seq_len,hsize_t,size_t);
FUNC_LEAVE (SUCCEED);
} /* end H5T_vlen_seq_mem_write() */
@@ -316,7 +316,8 @@ herr_t H5T_vlen_str_mem_read(H5F_t UNUSED *f, void *vl_addr, void *buf, size_t l
herr_t H5T_vlen_str_mem_write(const H5D_xfer_t *xfer_parms, H5F_t UNUSED *f, void *vl_addr, void *buf, hsize_t seq_len, hsize_t base_size)
{
char **s=(char **)vl_addr; /* Pointer to the user's hvl_t information */
- size_t len=seq_len*base_size;
+ size_t len;
+ H5_CHECK_OVERFLOW(((seq_len+1)*base_size),hsize_t,size_t);
FUNC_ENTER (H5T_vlen_str_mem_write, FAIL);
@@ -324,7 +325,7 @@ herr_t H5T_vlen_str_mem_write(const H5D_xfer_t *xfer_parms, H5F_t UNUSED *f, voi
assert(buf);
/* Use the user's memory allocation routine is one is defined */
- assert(((seq_len+1)*base_size)==(hsize_t)((size_t)((seq_len+1)*base_size))); /*check for overflow*/
+
if(xfer_parms->vlen_alloc!=NULL) {
if(NULL==(*s=(xfer_parms->vlen_alloc)((size_t)((seq_len+1)*base_size),xfer_parms->alloc_info)))
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data");
@@ -334,6 +335,7 @@ herr_t H5T_vlen_str_mem_write(const H5D_xfer_t *xfer_parms, H5F_t UNUSED *f, voi
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data");
} /* end else */
+ len=(size_t)seq_len*base_size;
HDmemcpy(*s,buf,len);
(*s)[len]='\0';
@@ -434,7 +436,7 @@ herr_t H5T_vlen_disk_write(const H5D_xfer_t UNUSED *xfer_parms, H5F_t *f, void *
{
uint8_t *vl=(uint8_t *)vl_addr; /* Pointer to the user's hvl_t information */
H5HG_t hobjid;
- size_t len=seq_len*base_size;
+ size_t len;
FUNC_ENTER (H5T_vlen_disk_write, FAIL);
@@ -444,11 +446,13 @@ herr_t H5T_vlen_disk_write(const H5D_xfer_t UNUSED *xfer_parms, H5F_t *f, void *
assert(f);
/* Set the length of the sequence */
+ H5_CHECK_OVERFLOW(seq_len,hsize_t,size_t);
UINT32ENCODE(vl, seq_len);
/* Check if this sequence actually has any data */
if(seq_len!=0) {
/* Write the VL information to disk (allocates space also) */
+ H5_ASSIGN_OVERFLOW(len,(seq_len*base_size),hsize_t,size_t);
if(H5HG_insert(f,len,buf,&hobjid)<0)
HRETURN_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to write VL information");
} /* end if */
diff --git a/src/H5V.c b/src/H5V.c
index e792585..5c72e92 100644
--- a/src/H5V.c
+++ b/src/H5V.c
@@ -751,6 +751,7 @@ H5V_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *size,
for (i=0; i<nelmts; i++) {
/* Copy an element */
+ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t);
HDmemcpy(dst, src, (size_t)elmt_size);
/* Decrement indices and advance pointers */
@@ -765,7 +766,7 @@ H5V_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *size,
}
}
} else {
- assert(elmt_size==(hsize_t)((size_t)elmt_size)); /*check for overflow*/
+ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t); /*check for overflow*/
HDmemcpy (dst, src, (size_t)elmt_size);
HRETURN (SUCCEED);
}
diff --git a/src/H5private.h b/src/H5private.h
index 15996c6..08a3201 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -437,6 +437,23 @@ Move H5_inline into windows version of H5pubconf.h; avoid duplicating warnings.
#define H5_CHECK_OVERFLOW(var,vartype,casttype)
#endif /* NDEBUG */
+
+/*
+ * A macro for detecting over/under-flow when assigning between types
+ */
+#ifndef NDEBUG
+#define H5_ASSIGN_OVERFLOW(var,expr,vartype,casttype) \
+{ \
+ vartype _tmp_overflow=(vartype)(expr); \
+ casttype _tmp_overflow2=(casttype)(_tmp_overflow); \
+ assert((casttype)_tmp_overflow==_tmp_overflow2); \
+ (var)=_tmp_overflow2; \
+}
+#else /* NDEBUG */
+#define H5_ASSIGN_OVERFLOW(var,expr,vartype,casttype) \
+ (var)=(casttype)(expr);
+#endif /* NDEBUG */
+
/*
* Data types and functions for timing certain parts of the library.
*/