summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5A.c74
-rw-r--r--src/H5B.c6
-rw-r--r--src/H5D.c23
-rw-r--r--src/H5Distore.c42
-rw-r--r--src/H5Dprivate.h2
-rw-r--r--src/H5F.c3
-rw-r--r--src/H5FD.c21
-rw-r--r--src/H5FDcore.c17
-rw-r--r--src/H5FDdpss.c2
-rw-r--r--src/H5FDfamily.c32
-rw-r--r--src/H5FDlog.c2
-rw-r--r--src/H5Farray.c11
-rw-r--r--src/H5Fistore.c42
-rw-r--r--src/H5Fpkg.h6
-rw-r--r--src/H5O.c1
-rw-r--r--src/H5Oattr.c40
-rw-r--r--src/H5Oefl.c40
-rw-r--r--src/H5P.c6
-rw-r--r--src/H5R.c16
-rw-r--r--src/H5Sall.c28
-rw-r--r--src/H5Shyper.c126
-rw-r--r--src/H5Smpio.c2
-rw-r--r--src/H5T.c14
-rw-r--r--src/H5TB.c12
-rw-r--r--src/H5Tconv.c1040
-rw-r--r--src/H5Tvlen.c22
-rw-r--r--src/H5V.c3
27 files changed, 844 insertions, 789 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 4b21749..5b474d0 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -247,12 +247,11 @@ 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(space)*H5T_get_size(type);
+ H5_ASSIGN_OVERFLOW(attr->data_size,H5S_get_simple_extent_npoints(space)*H5T_get_size(type),hssize_t,size_t);
/* Hold the symbol table entry (and file) open */
- if (H5O_open(&(attr->ent)) < 0) {
+ if (H5O_open(&(attr->ent)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open");
- }
attr->ent_opened=1;
/* Read in the existing attributes to check for duplicates */
@@ -503,10 +502,8 @@ H5A_open(H5G_entry_t *ent, unsigned idx)
/* Read in attribute with H5O_read() */
H5_CHECK_OVERFLOW(idx,unsigned,int);
- if (NULL==(attr=H5O_read(ent, H5O_ATTR, (int)idx, attr))) {
- HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL,
- "unable to load attribute info from dataset header");
- }
+ if (NULL==(attr=H5O_read(ent, H5O_ATTR, (int)idx, attr)))
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to load attribute info from dataset header");
attr->initialized=1;
/* Copy the symbol table entry */
@@ -612,7 +609,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;
@@ -630,31 +627,22 @@ 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 */
/* Set up type conversion function */
if (NULL == (tpath = H5T_path_find(mem_type, attr->dt, NULL, NULL))) {
- HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL,
- "unable to convert between src and dest data types");
+ HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types");
} else if (!H5T_IS_NOOP(tpath)) {
- if ((src_id = H5I_register(H5I_DATATYPE,
- H5T_copy(mem_type, H5T_COPY_ALL)))<0 ||
- (dst_id = H5I_register(H5I_DATATYPE,
- H5T_copy(attr->dt, H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, FAIL,
- "unable to register types for conversion");
- }
+ if ((src_id = H5I_register(H5I_DATATYPE, H5T_copy(mem_type, H5T_COPY_ALL)))<0 ||
+ (dst_id = H5I_register(H5I_DATATYPE, H5T_copy(attr->dt, H5T_COPY_ALL)))<0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, FAIL, "unable to register types for conversion");
}
/* Perform data type conversion */
@@ -775,7 +763,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);
@@ -792,45 +780,33 @@ 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*/
+ H5_CHECK_OVERFLOW((src_type_size*nelmts),hsize_t,size_t);
HDmemcpy(tconv_buf,attr->data,(size_t)(src_type_size*nelmts));
/* Convert memory buffer into disk buffer */
/* Set up type conversion function */
if (NULL == (tpath = H5T_path_find(attr->dt, mem_type, NULL, NULL))) {
- HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL,
- "unable to convert between src and dest data types");
+ HGOTO_ERROR(H5E_ATTR, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types");
} else if (!H5T_IS_NOOP(tpath)) {
- if ((src_id = H5I_register(H5I_DATATYPE,
- H5T_copy(attr->dt, H5T_COPY_ALL)))<0 ||
- (dst_id = H5I_register(H5I_DATATYPE,
- H5T_copy(mem_type, H5T_COPY_ALL)))<0) {
- HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, FAIL,
- "unable to register types for conversion");
- }
+ if ((src_id = H5I_register(H5I_DATATYPE, H5T_copy(attr->dt, H5T_COPY_ALL)))<0 ||
+ (dst_id = H5I_register(H5I_DATATYPE, H5T_copy(mem_type, H5T_COPY_ALL)))<0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTREGISTER, FAIL, "unable to register types for conversion");
}
/* Perform data type conversion. */
- if (H5T_convert(tpath, src_id, dst_id, nelmts, 0, 0, tconv_buf, bkg_buf,
- H5P_DEFAULT)<0) {
- HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL,
- "data type conversion failed");
- }
+ if (H5T_convert(tpath, src_id, dst_id, nelmts, 0, 0, tconv_buf, bkg_buf, H5P_DEFAULT)<0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "data type conversion failed");
/* Copy the converted data into the user's buffer */
HDmemcpy(buf,tconv_buf,(size_t)(dst_type_size*nelmts));
diff --git a/src/H5B.c b/src/H5B.c
index 7ff8f73..40cadad 100644
--- a/src/H5B.c
+++ b/src/H5B.c
@@ -724,11 +724,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/H5D.c b/src/H5D.c
index 81927aa..32595f4 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -152,7 +152,7 @@ H5D_init_interface(void)
hid_t def_vfl_id = H5D_XFER_VFL_ID_DEF;
void *def_vfl_info = H5D_XFER_VFL_INFO_DEF;
#ifdef COALESCE_READS
- unsigned def_gather_reads = H5D_XFER_GATHER_READS_DEF;
+ hsize_t def_gather_reads = H5D_XFER_GATHER_READS_DEF;
#endif /* COALESCE_READS */
size_t def_hyp_vec_size = H5D_XFER_HYPER_VECTOR_SIZE_DEF;
@@ -3087,7 +3087,9 @@ H5D_get_file (const H5D_t *dset)
static herr_t
H5D_init_storage(H5D_t *dset, const H5S_t *space)
{
- hssize_t npoints, ptsperbuf;
+ hssize_t snpoints; /* Number of points in space (for error checking) */
+ size_t npoints; /* Number of points in space */
+ size_t ptsperbuf;
size_t bufsize=8*1024;
size_t size;
haddr_t addr;
@@ -3119,23 +3121,25 @@ H5D_init_storage(H5D_t *dset, const H5S_t *space)
* even if it is all zero. This allows the application to force
* filling when the underlying storage isn't initialized to zero.
*/
- npoints = H5S_get_simple_extent_npoints(space);
+ snpoints = H5S_get_simple_extent_npoints(space);
+ assert(snpoints>=0);
+ H5_ASSIGN_OVERFLOW(npoints,snpoints,hssize_t,size_t);
- if (fill.buf && npoints==H5S_get_select_npoints(space)) {
+ if (fill.buf && npoints==(size_t)H5S_get_select_npoints(space)) {
/*
* Fill the entire current extent with the fill value. We can do
* this quite efficiently by making sure we copy the fill value
* in relatively large pieces.
*/
- ptsperbuf = (hssize_t)MAX(1, bufsize/fill.size);
- bufsize = ptsperbuf * fill.size;
+
+ ptsperbuf = MAX(1, bufsize/fill.size);
+ bufsize = ptsperbuf*fill.size;
/* Allocate temporary buffer */
if ((buf=H5FL_BLK_ALLOC(fill_conv,bufsize,0))==NULL)
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for fill buffer");
- assert(ptsperbuf==(hssize_t)((size_t)ptsperbuf)); /*check for overflow*/
- H5V_array_fill(buf, fill.buf, fill.size, (size_t)ptsperbuf);
+ H5V_array_fill(buf, fill.buf, fill.size, ptsperbuf);
if (efl.nused) {
addr = 0;
} else {
@@ -3148,8 +3152,7 @@ H5D_init_storage(H5D_t *dset, const H5S_t *space)
if(H5O_efl_write(dset->ent.file, &efl, addr, size, buf) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to write fill value to dataset");
} else {
- if (H5F_block_write(dset->ent.file, H5FD_MEM_DRAW, addr,
- size, H5P_DATASET_XFER_DEFAULT, buf)<0)
+ if (H5F_block_write(dset->ent.file, H5FD_MEM_DRAW, addr, size, H5P_DATASET_XFER_DEFAULT, buf)<0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to write fill value to dataset");
}
npoints -= MIN(ptsperbuf, npoints);
diff --git a/src/H5Distore.c b/src/H5Distore.c
index ed3c673..d016961 100644
--- a/src/H5Distore.c
+++ b/src/H5Distore.c
@@ -1216,7 +1216,7 @@ H5F_istore_prune (H5F_t *f, size_t size)
H5F_rdcc_t *rdcc = &(f->shared->rdcc);
size_t total = f->shared->rdcc_nbytes;
const int nmeth=2; /*number of methods */
- int w[1]; /*weighting as an interval */
+ int w[1]; /*weighting as an interval */
H5F_rdcc_ent_t *p[2], *cur; /*list pointers */
H5F_rdcc_ent_t *n[2]; /*list next pointers */
@@ -1232,7 +1232,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;
@@ -1337,13 +1337,14 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
unsigned *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 */
@@ -1358,7 +1359,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];
@@ -1391,9 +1392,10 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
HDfflush(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,
@@ -1405,10 +1407,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,17 @@ 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;
@@ -1708,7 +1713,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 */
unsigned idx_hint=0; /*cache index hint */
@@ -1823,9 +1828,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);
+ 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");
}
@@ -1883,7 +1889,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;
unsigned idx_hint=0;
- size_t chunk_size, naccessed;
+ hsize_t chunk_size, naccessed;
FUNC_ENTER(H5F_istore_write, FAIL);
@@ -1942,7 +1948,7 @@ H5F_istore_write(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
offset_f[u]+size[u]) -
(chunk_offset[u] + offset_wrt_chunk[u]);
naccessed *= sub_size[u];
-
+
/* Offset into mem buffer */
sub_offset_m[u] = chunk_offset[u] + offset_wrt_chunk[u] +
offset_m[u] - offset_f[u];
@@ -2001,9 +2007,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");
}
@@ -2330,7 +2337,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;
unsigned idx_hint=0;
- size_t chunk_size;
+ hsize_t chunk_size;
#ifdef AKC
H5F_istore_ud1_t udata;
#endif
@@ -2395,8 +2402,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/H5Dprivate.h b/src/H5Dprivate.h
index a66db7b..0e51a4b 100644
--- a/src/H5Dprivate.h
+++ b/src/H5Dprivate.h
@@ -132,7 +132,7 @@
#ifdef COALESCE_READS
/* Definitions for 'gather reads' property */
#define H5D_XFER_GATHER_READS_NAME "gather_reads"
-#define H5D_XFER_GATHER_READS_SIZE sizeof(unsigned)
+#define H5D_XFER_GATHER_READS_SIZE sizeof(hsize_t)
#define H5D_XFER_GATHER_READS_DEF 0
#endif /* COALESCE_READS */
/* Definitions for hyperslab vector size property */
diff --git a/src/H5F.c b/src/H5F.c
index 3fdd5e8..5c457b7 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -2043,7 +2043,8 @@ H5F_flush(H5F_t *f, H5F_scope_t scope, hbool_t invalidate,
/*
* Encode the driver information block.
*/
- if ((driver_size=H5FD_sb_size(f->shared->lf))) {
+ H5_ASSIGN_OVERFLOW(driver_size,H5FD_sb_size(f->shared->lf),hsize_t,size_t);
+ if (driver_size>0) {
driver_size += 16; /*driver block header */
assert(driver_size<=sizeof(dbuf));
p = dbuf;
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) {
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;
diff --git a/src/H5FDdpss.c b/src/H5FDdpss.c
index 539f9ec..87f86f5 100644
--- a/src/H5FDdpss.c
+++ b/src/H5FDdpss.c
@@ -553,7 +553,7 @@ H5FD_dpss_read (H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t dxpl_id, haddr_t ad
H5P_genplist_t *plist; /* Property list pointer */
globus_result_t globus_result;
#ifdef COALESCE_READS
- static int count = 0; /* counter for single reads */
+ static hsize_t count = 0; /* counter for single reads */
#endif
FUNC_ENTER (H5FD_dpss_read, FAIL);
diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c
index 0ecf171..80feac2 100644
--- a/src/H5FDfamily.c
+++ b/src/H5FDfamily.c
@@ -863,6 +863,9 @@ H5FD_family_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, si
int i;
haddr_t sub;
size_t req;
+#ifndef NDEBUG
+ hsize_t tempreq;
+#endif /* NDEBUG */
H5P_genplist_t *plist; /* Property list pointer */
FUNC_ENTER(H5FD_family_read, FAIL);
@@ -883,9 +886,18 @@ H5FD_family_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, si
/* 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)
@@ -929,6 +941,9 @@ H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, s
int i;
haddr_t sub;
size_t req;
+#ifndef NDEBUG
+ hsize_t tempreq;
+#endif /* NDEBUG */
H5P_genplist_t *plist; /* Property list pointer */
FUNC_ENTER(H5FD_family_write, FAIL);
@@ -949,9 +964,18 @@ H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, s
/* 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 aa2bcb2..a9f76af 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -749,7 +749,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 5874b67..6b4155c 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 */
@@ -153,7 +153,7 @@ H5F_arr_read(H5F_t *f, hid_t dxpl_id, const struct H5O_layout_t *layout,
H5P_genplist_t *plist=NULL; /* Property list */
#endif
#ifdef COALESCE_READS
- unsigned gather_reads; /* # of MPIO reads to gather */
+ hsize_t gather_reads; /* # of MPIO reads to gather */
#endif
FUNC_ENTER(H5F_arr_read, FAIL);
@@ -242,8 +242,7 @@ 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*/);
+ 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,
@@ -311,7 +310,6 @@ H5F_arr_read(H5F_t *f, hid_t dxpl_id, const struct H5O_layout_t *layout,
/* Track the number of reads to gather */
if(H5P_set(plist, H5D_XFER_GATHER_READS_NAME, &gather_reads)<0)
HRETURN_ERROR (H5E_PLIST, H5E_CANTGET, FAIL, "Can't retrieve gather reads");
-
#else
for (z=0; z<nelmts; z++) {
#endif
@@ -433,7 +431,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 */
@@ -548,6 +546,7 @@ H5F_arr_write(H5F_t *f, hid_t dxpl_id, const struct H5O_layout_t *layout,
*/
H5V_vector_cpy(ndims, idx, hslab_size);
nelmts = H5V_vector_reduce_product(ndims, hslab_size);
+
if (efl && efl->nused>0) {
addr = 0;
} else {
diff --git a/src/H5Fistore.c b/src/H5Fistore.c
index ed3c673..d016961 100644
--- a/src/H5Fistore.c
+++ b/src/H5Fistore.c
@@ -1216,7 +1216,7 @@ H5F_istore_prune (H5F_t *f, size_t size)
H5F_rdcc_t *rdcc = &(f->shared->rdcc);
size_t total = f->shared->rdcc_nbytes;
const int nmeth=2; /*number of methods */
- int w[1]; /*weighting as an interval */
+ int w[1]; /*weighting as an interval */
H5F_rdcc_ent_t *p[2], *cur; /*list pointers */
H5F_rdcc_ent_t *n[2]; /*list next pointers */
@@ -1232,7 +1232,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;
@@ -1337,13 +1337,14 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
unsigned *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 */
@@ -1358,7 +1359,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];
@@ -1391,9 +1392,10 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
HDfflush(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,
@@ -1405,10 +1407,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,17 @@ 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;
@@ -1708,7 +1713,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 */
unsigned idx_hint=0; /*cache index hint */
@@ -1823,9 +1828,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);
+ 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");
}
@@ -1883,7 +1889,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;
unsigned idx_hint=0;
- size_t chunk_size, naccessed;
+ hsize_t chunk_size, naccessed;
FUNC_ENTER(H5F_istore_write, FAIL);
@@ -1942,7 +1948,7 @@ H5F_istore_write(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout,
offset_f[u]+size[u]) -
(chunk_offset[u] + offset_wrt_chunk[u]);
naccessed *= sub_size[u];
-
+
/* Offset into mem buffer */
sub_offset_m[u] = chunk_offset[u] + offset_wrt_chunk[u] +
offset_m[u] - offset_f[u];
@@ -2001,9 +2007,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");
}
@@ -2330,7 +2337,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;
unsigned idx_hint=0;
- size_t chunk_size;
+ hsize_t chunk_size;
#ifdef AKC
H5F_istore_ud1_t udata;
#endif
@@ -2395,8 +2402,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 22cae65..0bff2a8 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -61,6 +61,12 @@
#else
# define H5F_OVERFLOW_SIZET2OFFT(X) 0
#endif
+#if (H5_SIZEOF_HSIZE_T >= 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_SIZET2OFFT(X) 0
+#endif
/* The raw data chunk cache */
typedef struct H5F_rdcc_t {
diff --git a/src/H5O.c b/src/H5O.c
index a4a3ed4..891a004 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -379,6 +379,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_DATASET_XFER_DEFAULT, buf) < 0) {
HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL,
"unable to read object header");
diff --git a/src/H5Oattr.c b/src/H5Oattr.c
index c96a2ce..951ffbb 100644
--- a/src/H5Oattr.c
+++ b/src/H5Oattr.c
@@ -94,7 +94,7 @@ H5O_attr_decode(H5F_t *f, const uint8_t *p, H5O_shared_t UNUSED *sh)
H5A_t *attr = NULL;
H5S_simple_t *simple; /*simple dimensionality information */
size_t name_len; /*attribute name length */
- int version; /*message version number*/
+ int version; /*message version number*/
FUNC_ENTER(H5O_attr_decode, NULL);
@@ -102,17 +102,13 @@ H5O_attr_decode(H5F_t *f, const uint8_t *p, H5O_shared_t UNUSED *sh)
assert(f);
assert(p);
- if (NULL==(attr = H5MM_calloc(sizeof(H5A_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
+ if (NULL==(attr = H5MM_calloc(sizeof(H5A_t))))
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
/* Version number */
version = *p++;
- if (version!=H5O_ATTR_VERSION) {
- HRETURN_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL,
- "bad version number for attribute message");
- }
+ if (version!=H5O_ATTR_VERSION)
+ HRETURN_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "bad version number for attribute message");
/* Reserved */
p++;
@@ -126,25 +122,19 @@ H5O_attr_decode(H5F_t *f, const uint8_t *p, H5O_shared_t UNUSED *sh)
UINT16DECODE(p, attr->ds_size);
/* Decode and store the name */
- if (NULL==(attr->name=H5MM_malloc(name_len))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
+ if (NULL==(attr->name=H5MM_malloc(name_len)))
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
HDmemcpy(attr->name,p,name_len);
p += H5O_ALIGN(name_len); /* advance the memory pointer */
/* decode the attribute datatype */
- if((attr->dt=(H5O_DTYPE->decode)(f,p,NULL))==NULL) {
- HRETURN_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL,
- "can't decode attribute datatype");
- }
+ if((attr->dt=(H5O_DTYPE->decode)(f,p,NULL))==NULL)
+ HRETURN_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute datatype");
p += H5O_ALIGN(attr->dt_size);
/* decode the attribute dataspace */
- if (NULL==(attr->ds = H5FL_ALLOC(H5S_t,1))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
+ if (NULL==(attr->ds = H5FL_ALLOC(H5S_t,1)))
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
if((simple=(H5O_SDSPACE->decode)(f,p,NULL))!=NULL) {
attr->ds->extent.type = H5S_SIMPLE;
HDmemcpy(&(attr->ds->extent.u.simple),simple, sizeof(H5S_simple_t));
@@ -155,13 +145,11 @@ H5O_attr_decode(H5F_t *f, const uint8_t *p, H5O_shared_t UNUSED *sh)
p += H5O_ALIGN(attr->ds_size);
/* Compute the size of the data */
- 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(attr->ds)*H5T_get_size(attr->dt),hsize_t,size_t);
/* Go get the data */
- if (NULL==(attr->data = H5MM_malloc(attr->data_size))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
+ if (NULL==(attr->data = H5MM_malloc(attr->data_size)))
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
HDmemcpy(attr->data,p,attr->data_size);
/* Indicate that the fill values aren't to be written out */
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");
diff --git a/src/H5P.c b/src/H5P.c
index 9d03f27..71e14bc 100644
--- a/src/H5P.c
+++ b/src/H5P.c
@@ -1452,7 +1452,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;
H5O_efl_t efl;
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value=FAIL; /* return value */
@@ -1484,8 +1484,8 @@ H5Pset_external(hid_t plist_id, const char *name, off_t offset, hsize_t size)
tmp = total + efl.slot[idx].size;
if (tmp <= total)
HGOTO_ERROR (H5E_EFL, H5E_OVERFLOW, FAIL, "total external data size overflowed");
- }
- }
+ } /* end for */
+ } /* end if */
/* Add to the list */
diff --git a/src/H5R.c b/src/H5R.c
index f510b39..23d4184 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;
@@ -213,14 +211,12 @@ H5R_create(void *_ref, H5G_entry_t *loc, const char *name, H5R_type_t ref_type,
/* Serialize the selection */
if (H5S_select_serialize(space,p) < 0)
- HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL,
- "Unable to serialize selection");
+ HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL, "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");
+ HGOTO_ERROR(H5E_REFERENCE, H5E_WRITEERROR, FAIL, "Unable to serialize selection");
/* Serialize the heap ID and index for storage in the file */
p=(uint8_t *)ref->heapid;
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 */
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index b72020e..77000e5 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -449,8 +449,7 @@ printf("%s: Called!\n",FUNC);
ispan=iter->hyp.span;
/* Set the amount of elements to perform I/O on, etc. */
- assert(nelem==(hsize_t)((size_t)(nelem))); /*check for overflow*/
- io_bytes_left=nelem*elmt_size;
+ H5_ASSIGN_OVERFLOW(io_bytes_left,(nelem*elmt_size),hsize_t,size_t);
/* Compute the cumulative size of dataspace dimensions */
for(i=fast_dim, acc=elmt_size; i>=0; i--) {
@@ -484,7 +483,7 @@ printf("%s: Called!\n",FUNC);
/* Finish the span in the fastest changing dimension */
/* Compute the number of bytes to attempt in this span */
- span_size=((curr_span->high-abs_arr[fast_dim])+1)*elmt_size;
+ H5_ASSIGN_OVERFLOW(span_size,((curr_span->high-abs_arr[fast_dim])+1)*elmt_size,hsize_t,size_t);
/* Check number of bytes against upper bounds allowed */
if(span_size>io_bytes_left)
@@ -632,8 +631,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
loc_off+=curr_span->pstride;
/* Compute the number of elements to attempt in this span */
- assert(curr_span->nelem==(hsize_t)((size_t)(curr_span->nelem))); /*check for overflow*/
- span_size=curr_span->nelem;
+ H5_ASSIGN_OVERFLOW(span_size,curr_span->nelem,hsize_t,size_t);
/* Check number of elements against upper bounds allowed */
if(span_size>=io_bytes_left) {
@@ -868,9 +866,9 @@ H5S_hyper_fread_opt (H5F_t *f, const struct H5O_layout_t *layout,
fast_dim_offset;
hsize_t fast_dim_stride, /* Local copies of fastest changing dimension info */
fast_dim_block,
- fast_dim_count,
fast_dim_buf_off;
- hsize_t tot_blk_count; /* Total number of blocks left to output */
+ size_t fast_dim_count;
+ size_t tot_blk_count; /* Total number of blocks left to output */
size_t act_blk_count; /* Actual number of blocks to output */
int fast_dim; /* Rank of the fastest changing dimension for the dataspace */
int temp_dim; /* Temporary rank holder */
@@ -931,8 +929,7 @@ for(i=0; i<file_space->extent.u.simple.rank; i++)
} /* end for */
/* Set the number of elements left for I/O */
- assert(nelmts==(hsize_t)((size_t)nelmts)); /*check for overflow*/
- io_left=(size_t)nelmts;
+ H5_ASSIGN_OVERFLOW(io_left,nelmts,hsize_t,size_t);
#ifdef QAK
printf("%s: fast_dim=%d\n",FUNC,(int)fast_dim);
@@ -954,7 +951,7 @@ printf("%s: Check 1.0\n",FUNC);
leftover=file_space->select.sel_info.hslab.diminfo[fast_dim].block-((file_iter->hyp.pos[fast_dim]-file_space->select.sel_info.hslab.diminfo[fast_dim].start)%file_space->select.sel_info.hslab.diminfo[fast_dim].stride);
/* Make certain that we don't read too many */
- actual_read=MIN(leftover,nelmts);
+ actual_read=MIN(leftover,io_left);
actual_bytes=actual_read*elmt_size;
/* Copy the location of the point to get */
@@ -1042,7 +1039,7 @@ for(i=0; i<ndims; i++) {
buf_off+=offset[i]*slab[i];
/* Set the number of elements to read each time */
- actual_read=file_space->select.sel_info.hslab.diminfo[fast_dim].block;
+ H5_ASSIGN_OVERFLOW(actual_read,file_space->select.sel_info.hslab.diminfo[fast_dim].block,hsize_t,size_t);
/* Set the number of actual bytes */
actual_bytes=actual_read*elmt_size;
@@ -1087,7 +1084,7 @@ for(i=0; i<file_space->extent.u.simple.rank; i++)
/* Read in data until an entire sequence can't be read in any longer */
while(io_left>0) {
/* Reset copy of number of blocks in fastest dimension */
- fast_dim_count=tdiminfo[fast_dim].count-tmp_count[fast_dim];
+ H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count-tmp_count[fast_dim],hsize_t,size_t);
/* Check if this entire row will fit into buffer */
if(fast_dim_count<=tot_blk_count) {
@@ -1551,8 +1548,7 @@ printf("%s: Called!\n",FUNC);
ispan=iter->hyp.span;
/* Set the amount of elements to perform I/O on, etc. */
- assert(nelem==(hsize_t)((size_t)(nelem))); /*check for overflow*/
- io_bytes_left=nelem*elmt_size;
+ H5_ASSIGN_OVERFLOW(io_bytes_left,(nelem*elmt_size),hsize_t,size_t);
/* Compute the cumulative size of dataspace dimensions */
for(i=fast_dim, acc=elmt_size; i>=0; i--) {
@@ -1586,7 +1582,7 @@ printf("%s: Called!\n",FUNC);
/* Finish the span in the fastest changing dimension */
/* Compute the number of bytes to attempt in this span */
- span_size=((curr_span->high-abs_arr[fast_dim])+1)*elmt_size;
+ H5_ASSIGN_OVERFLOW(span_size,((curr_span->high-abs_arr[fast_dim])+1)*elmt_size,hsize_t,size_t);
/* Check number of bytes against upper bounds allowed */
if(span_size>io_bytes_left)
@@ -1734,8 +1730,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
loc_off+=curr_span->pstride;
/* Compute the number of elements to attempt in this span */
- assert(curr_span->nelem==(hsize_t)((size_t)(curr_span->nelem))); /*check for overflow*/
- span_size=curr_span->nelem;
+ H5_ASSIGN_OVERFLOW(span_size,curr_span->nelem,hsize_t,size_t);
/* Check number of elements against upper bounds allowed */
if(span_size>=io_bytes_left) {
@@ -1970,9 +1965,9 @@ H5S_hyper_fwrite_opt (H5F_t *f, const struct H5O_layout_t *layout,
fast_dim_offset;
hsize_t fast_dim_stride, /* Local copies of fastest changing dimension info */
fast_dim_block,
- fast_dim_count,
fast_dim_buf_off;
- hsize_t tot_blk_count; /* Total number of blocks left to output */
+ size_t fast_dim_count;
+ size_t tot_blk_count; /* Total number of blocks left to output */
size_t act_blk_count; /* Actual number of blocks to output */
int fast_dim; /* Rank of the fastest changing dimension for the dataspace */
int temp_dim; /* Temporary rank holder */
@@ -2033,8 +2028,7 @@ for(i=0; i<file_space->extent.u.simple.rank; i++)
} /* end for */
/* Set the number of elements left for I/O */
- assert(nelmts==(hsize_t)((size_t)nelmts)); /*check for overflow*/
- io_left=(size_t)nelmts;
+ H5_ASSIGN_OVERFLOW(io_left,nelmts,hsize_t,size_t);
#ifdef QAK
printf("%s: fast_dim=%d\n",FUNC,(int)fast_dim);
@@ -2056,7 +2050,7 @@ printf("%s: Check 1.0\n",FUNC);
leftover=file_space->select.sel_info.hslab.diminfo[fast_dim].block-((file_iter->hyp.pos[fast_dim]-file_space->select.sel_info.hslab.diminfo[fast_dim].start)%file_space->select.sel_info.hslab.diminfo[fast_dim].stride);
/* Make certain that we don't write too many */
- actual_write=MIN(leftover,nelmts);
+ actual_write=MIN(leftover,io_left);
actual_bytes=actual_write*elmt_size;
/* Copy the location of the point to get */
@@ -2144,7 +2138,7 @@ for(i=0; i<ndims; i++) {
buf_off+=offset[i]*slab[i];
/* Set the number of elements to write each time */
- actual_write=file_space->select.sel_info.hslab.diminfo[fast_dim].block;
+ H5_ASSIGN_OVERFLOW(actual_write,file_space->select.sel_info.hslab.diminfo[fast_dim].block,hsize_t,size_t);
/* Set the number of actual bytes */
actual_bytes=actual_write*elmt_size;
@@ -2189,7 +2183,7 @@ for(i=0; i<file_space->extent.u.simple.rank; i++)
/* Write out data until an entire sequence can't be written any longer */
while(io_left>0) {
/* Reset copy of number of blocks in fastest dimension */
- fast_dim_count=tdiminfo[fast_dim].count-tmp_count[fast_dim];
+ H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count-tmp_count[fast_dim],hsize_t,size_t);
/* Check if this entire row will fit into buffer */
if(fast_dim_count<=tot_blk_count) {
@@ -2634,8 +2628,7 @@ printf("%s: Called!\n",FUNC);
ispan=iter->hyp.span;
/* Set the amount of elements to perform I/O on, etc. */
- assert(nelem==(hsize_t)((size_t)(nelem))); /*check for overflow*/
- io_bytes_left=nelem*elmt_size;
+ H5_ASSIGN_OVERFLOW(io_bytes_left,nelem*elmt_size,hsize_t,size_t);
/* Compute the cumulative size of dataspace dimensions */
for(i=fast_dim, acc=elmt_size; i>=0; i--) {
@@ -2657,13 +2650,13 @@ printf("%s: Called!\n",FUNC);
/* Finish the span in the fastest changing dimension */
/* Compute the number of bytes to attempt in this span */
- span_size=((curr_span->high-abs_arr[fast_dim])+1)*elmt_size;
+ H5_ASSIGN_OVERFLOW(span_size,((curr_span->high-abs_arr[fast_dim])+1)*elmt_size,hsize_t,size_t);
/* Check number of elements against upper bounds allowed */
if(span_size>io_bytes_left)
span_size=io_bytes_left;
- HDmemcpy(dst,tmp_src,(size_t)span_size);
+ HDmemcpy(dst,tmp_src,span_size);
/* Increment offset in destination */
dst+=span_size;
@@ -2800,8 +2793,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
tmp_src+=curr_span->pstride;
/* Compute the number of elements to attempt in this span */
- assert(curr_span->nelem==(hsize_t)((size_t)(curr_span->nelem))); /*check for overflow*/
- span_size=curr_span->nelem;
+ H5_ASSIGN_OVERFLOW(span_size,curr_span->nelem,hsize_t,size_t);
/* Check number of elements against upper bounds allowed */
if(span_size>=io_bytes_left) {
@@ -2811,7 +2803,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
/* COMMON */
/* "Read" the data from the source buffer */
- HDmemcpy(dst,tmp_src,(size_t)span_size);
+ HDmemcpy(dst,tmp_src,span_size);
/* Increment offset in destination */
dst+=span_size;
@@ -2826,7 +2818,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
/* COMMON */
/* "Read" the data from the source buffer */
- HDmemcpy(dst,tmp_src,(size_t)span_size);
+ HDmemcpy(dst,tmp_src,span_size);
/* Increment offset in destination */
dst+=span_size;
@@ -2983,10 +2975,10 @@ H5S_hyper_mread_opt (const void *_buf, size_t elmt_size,
hssize_t fast_dim_start, /* Local copies of fastest changing dimension info */
fast_dim_offset;
hsize_t fast_dim_stride, /* Local copies of fastest changing dimension info */
- fast_dim_block,
- fast_dim_count;
- hsize_t tot_blk_count; /* Total number of blocks left to output */
- size_t act_blk_count; /* Actual number of blocks to output */
+ fast_dim_block;
+ size_t fast_dim_count;
+ size_t tot_blk_count; /* Total number of blocks left to output */
+ size_t act_blk_count; /* Actual number of blocks to output */
size_t fast_dim_buf_off; /* Local copy of amount to move fastest dimension buffer offset */
int fast_dim; /* Rank of the fastest changing dimension for the dataspace */
int temp_dim; /* Temporary rank holder */
@@ -2998,7 +2990,7 @@ H5S_hyper_mread_opt (const void *_buf, size_t elmt_size,
size_t actual_bytes; /* The actual number of bytes to copy */
size_t io_left; /* The number of elements left in I/O operation */
#ifndef NO_DUFFS_DEVICE
- hsize_t duffs_index; /* Counting index for Duff's device */
+ size_t duffs_index; /* Counting index for Duff's device */
#endif /* NO_DUFFS_DEVICE */
FUNC_ENTER (H5S_hyper_mread_opt, 0);
@@ -3036,13 +3028,12 @@ for(i=0; i<ndims; i++)
#endif /* QAK */
/* Set the number of elements left for I/O */
- assert(nelmts==(hsize_t)((size_t)nelmts)); /*check for overflow*/
- io_left=(size_t)nelmts;
+ H5_ASSIGN_OVERFLOW(io_left,nelmts,hsize_t,size_t);
/* Check if we stopped in the middle of a sequence of elements */
if((mem_iter->hyp.pos[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride!=0 ||
- ((mem_iter->hyp.pos[fast_dim]!=mem_space->select.sel_info.hslab.diminfo[fast_dim].start) && mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1)) {
- unsigned leftover; /* The number of elements left over from the last sequence */
+ ((mem_iter->hyp.pos[fast_dim]!=mem_space->select.sel_info.hslab.diminfo[fast_dim].start) && mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1)) {
+ size_t leftover; /* The number of elements left over from the last sequence */
#ifdef QAK
printf("%s: Check 1.0, io_left=%lu\n",FUNC,(unsigned long)io_left);
@@ -3054,7 +3045,7 @@ printf("%s: Check 1.0, io_left=%lu\n",FUNC,(unsigned long)io_left);
leftover=mem_space->select.sel_info.hslab.diminfo[fast_dim].block-((mem_iter->hyp.pos[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride);
/* Make certain that we don't write too many */
- actual_read=MIN(leftover,nelmts);
+ actual_read=MIN(leftover,io_left);
actual_bytes=actual_read*elmt_size;
/* Copy the location of the point to get */
@@ -3122,7 +3113,7 @@ printf("%s: Check 2.0, io_left=%lu\n",FUNC,(unsigned long)io_left);
src+=offset[i]*slab[i];
/* Set the number of elements to write each time */
- actual_read=mem_space->select.sel_info.hslab.diminfo[fast_dim].block;
+ H5_ASSIGN_OVERFLOW(actual_read,mem_space->select.sel_info.hslab.diminfo[fast_dim].block,hsize_t,size_t);
/* Set the number of actual bytes */
actual_bytes=actual_read*elmt_size;
@@ -3147,7 +3138,7 @@ for(i=0; i<ndims; i++)
fast_dim_start=tdiminfo[fast_dim].start;
fast_dim_stride=tdiminfo[fast_dim].stride;
fast_dim_block=tdiminfo[fast_dim].block;
- fast_dim_buf_off=slab[fast_dim]*fast_dim_stride;
+ H5_ASSIGN_OVERFLOW(fast_dim_buf_off,(slab[fast_dim]*fast_dim_stride),hsize_t,size_t);
fast_dim_offset=fast_dim_start+mem_space->select.offset[fast_dim];
/* Compute the number of blocks which would fit into the buffer */
@@ -3164,7 +3155,7 @@ for(i=0; i<ndims; i++)
/* Read in data until an entire sequence can't be written out any longer */
while(io_left>0) {
/* Reset copy of number of blocks in fastest dimension */
- fast_dim_count=tdiminfo[fast_dim].count-tmp_count[fast_dim];
+ H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count-tmp_count[fast_dim],hsize_t,size_t);
/* Check if this entire row will fit into buffer */
if(fast_dim_count<=tot_blk_count) {
@@ -3193,7 +3184,7 @@ for(i=0; i<ndims; i++)
* order to make the system compuiler happy. It can be
* removed when we are no longer supporting that platform. -QAK
*/
- switch (((size_t)fast_dim_count) % 8) {
+ switch (fast_dim_count % 8) {
case 0:
do
{
@@ -3510,8 +3501,7 @@ printf("%s: Called!\n",FUNC);
ispan=iter->hyp.span;
/* Set the amount of elements to perform I/O on, etc. */
- assert(nelem==(hsize_t)((size_t)(nelem))); /*check for overflow*/
- io_bytes_left=nelem*elmt_size;
+ H5_ASSIGN_OVERFLOW(io_bytes_left,nelem*elmt_size,hsize_t,size_t);
/* Compute the cumulative size of dataspace dimensions */
for(i=fast_dim, acc=elmt_size; i>=0; i--) {
@@ -3533,13 +3523,13 @@ printf("%s: Called!\n",FUNC);
/* Finish the span in the fastest changing dimension */
/* Compute the number of bytes to attempt in this span */
- span_size=((curr_span->high-abs_arr[fast_dim])+1)*elmt_size;
+ H5_ASSIGN_OVERFLOW(span_size,((curr_span->high-abs_arr[fast_dim])+1)*elmt_size,hsize_t,size_t);
/* Check number of elements against upper bounds allowed */
if(span_size>io_bytes_left)
span_size=io_bytes_left;
- HDmemcpy(tmp_dst,src,(size_t)span_size);
+ HDmemcpy(tmp_dst,src,span_size);
/* Increment offset in destination */
src+=span_size;
@@ -3676,8 +3666,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
tmp_dst+=(size_t)curr_span->pstride;
/* Compute the number of elements to attempt in this span */
- assert(curr_span->nelem==(hsize_t)((size_t)(curr_span->nelem))); /*check for overflow*/
- span_size=curr_span->nelem;
+ H5_ASSIGN_OVERFLOW(span_size,curr_span->nelem,hsize_t,size_t);
/* Check number of elements against upper bounds allowed */
if(span_size>=io_bytes_left) {
@@ -3687,7 +3676,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
/* COMMON */
/* "Write" the data into the destination buffer */
- HDmemcpy(tmp_dst,src,(size_t)span_size);
+ HDmemcpy(tmp_dst,src,span_size);
/* Increment offset in destination */
src+=span_size;
@@ -3702,7 +3691,7 @@ partial_done: /* Yes, goto's are evil, so sue me... :-) */
/* COMMON */
/* "Write" the data into the destination buffer */
- HDmemcpy(tmp_dst,src,(size_t)span_size);
+ HDmemcpy(tmp_dst,src,span_size);
/* Increment offset in destination */
src+=span_size;
@@ -3850,7 +3839,7 @@ H5S_hyper_mwrite_opt (const void *_tconv_buf, size_t elmt_size,
hsize_t slab[H5O_LAYOUT_NDIMS]; /* Hyperslab size */
hssize_t wrap[H5O_LAYOUT_NDIMS]; /* Bytes to wrap around at the end of a row */
hsize_t skip[H5O_LAYOUT_NDIMS]; /* Bytes to skip between blocks */
- hssize_t offset[H5O_LAYOUT_NDIMS]; /* Offset on disk */
+ hssize_t offset[H5O_LAYOUT_NDIMS]; /* Offset on disk */
hsize_t tmp_count[H5O_LAYOUT_NDIMS]; /* Temporary block count */
hsize_t tmp_block[H5O_LAYOUT_NDIMS]; /* Temporary block offset */
const uint8_t *src=(const uint8_t *)_tconv_buf; /* Alias for pointer arithmetic */
@@ -3859,9 +3848,9 @@ H5S_hyper_mwrite_opt (const void *_tconv_buf, size_t elmt_size,
hssize_t fast_dim_start, /* Local copies of fastest changing dimension info */
fast_dim_offset;
hsize_t fast_dim_stride, /* Local copies of fastest changing dimension info */
- fast_dim_block,
- fast_dim_count;
- hsize_t tot_blk_count; /* Total number of blocks left to output */
+ fast_dim_block;
+ size_t fast_dim_count;
+ size_t tot_blk_count; /* Total number of blocks left to output */
size_t act_blk_count; /* Actual number of blocks to output */
size_t fast_dim_buf_off; /* Local copy of amount to move fastest dimension buffer offset */
int fast_dim; /* Rank of the fastest changing dimension for the dataspace */
@@ -3874,7 +3863,7 @@ H5S_hyper_mwrite_opt (const void *_tconv_buf, size_t elmt_size,
size_t actual_bytes; /* The actual number of bytes to copy */
size_t io_left; /* The number of elements left in I/O operation */
#ifndef NO_DUFFS_DEVICE
- hsize_t duffs_index; /* Counting index for Duff's device */
+ size_t duffs_index; /* Counting index for Duff's device */
#endif /* NO_DUFFS_DEVICE */
FUNC_ENTER (H5S_hyper_mwrite_opt, 0);
@@ -3912,13 +3901,12 @@ for(i=0; i<ndims; i++)
#endif /* QAK */
/* Set the number of elements left for I/O */
- assert(nelmts==(hsize_t)((size_t)nelmts)); /*check for overflow*/
- io_left=(size_t)nelmts;
+ H5_ASSIGN_OVERFLOW(io_left,nelmts,hsize_t,size_t);
/* Check if we stopped in the middle of a sequence of elements */
if((mem_iter->hyp.pos[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride!=0 ||
- ((mem_iter->hyp.pos[fast_dim]!=mem_space->select.sel_info.hslab.diminfo[fast_dim].start) && mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1)) {
- unsigned leftover; /* The number of elements left over from the last sequence */
+ ((mem_iter->hyp.pos[fast_dim]!=mem_space->select.sel_info.hslab.diminfo[fast_dim].start) && mem_space->select.sel_info.hslab.diminfo[fast_dim].stride==1)) {
+ size_t leftover; /* The number of elements left over from the last sequence */
#ifdef QAK
printf("%s: Check 1.0, io_left=%lu\n",FUNC,(unsigned long)io_left);
@@ -3930,7 +3918,7 @@ printf("%s: Check 1.0, io_left=%lu\n",FUNC,(unsigned long)io_left);
leftover=mem_space->select.sel_info.hslab.diminfo[fast_dim].block-((mem_iter->hyp.pos[fast_dim]-mem_space->select.sel_info.hslab.diminfo[fast_dim].start)%mem_space->select.sel_info.hslab.diminfo[fast_dim].stride);
/* Make certain that we don't write too many */
- actual_write=MIN(leftover,nelmts);
+ actual_write=MIN(leftover,io_left);
actual_bytes=actual_write*elmt_size;
/* Copy the location of the point to get */
@@ -3998,7 +3986,7 @@ printf("%s: Check 2.0, io_left=%lu\n",FUNC,(unsigned long)io_left);
dst+=offset[i]*slab[i];
/* Set the number of elements to write each time */
- actual_write=mem_space->select.sel_info.hslab.diminfo[fast_dim].block;
+ H5_ASSIGN_OVERFLOW(actual_write,mem_space->select.sel_info.hslab.diminfo[fast_dim].block,hsize_t,size_t);
/* Set the number of actual bytes */
actual_bytes=actual_write*elmt_size;
@@ -4023,7 +4011,7 @@ for(i=0; i<ndims; i++)
fast_dim_start=tdiminfo[fast_dim].start;
fast_dim_stride=tdiminfo[fast_dim].stride;
fast_dim_block=tdiminfo[fast_dim].block;
- fast_dim_buf_off=slab[fast_dim]*fast_dim_stride;
+ H5_ASSIGN_OVERFLOW(fast_dim_buf_off,slab[fast_dim]*fast_dim_stride,hsize_t,size_t);
fast_dim_offset=fast_dim_start+mem_space->select.offset[fast_dim];
/* Compute the number of blocks which would fit into the buffer */
@@ -4040,7 +4028,7 @@ for(i=0; i<ndims; i++)
/* Read in data until an entire sequence can't be written out any longer */
while(io_left>0) {
/* Reset copy of number of blocks in fastest dimension */
- fast_dim_count=tdiminfo[fast_dim].count-tmp_count[fast_dim];
+ H5_ASSIGN_OVERFLOW(fast_dim_count,tdiminfo[fast_dim].count-tmp_count[fast_dim],hsize_t,size_t);
/* Check if this entire row will fit into buffer */
if(fast_dim_count<=tot_blk_count) {
@@ -4069,7 +4057,7 @@ for(i=0; i<ndims; i++)
* order to make the system compuiler happy. It can be
* removed when we are no longer supporting that platform. -QAK
*/
- switch (((size_t)fast_dim_count) % 8) {
+ switch (fast_dim_count % 8) {
case 0:
do
{
@@ -5901,7 +5889,7 @@ H5S_hyper_select_iterate_helper(H5S_hyper_iter_info_t *iter_info)
hsize_t loc_off; /* Element offset in the dataspace */
int i; /* Index variable */
unsigned u; /* Index variable */
- hssize_t ret_value=FAIL;
+ herr_t ret_value=FAIL;
FUNC_ENTER (H5S_hyper_select_iterate_helper, FAIL);
diff --git a/src/H5Smpio.c b/src/H5Smpio.c
index 73afb72..89eadd6 100644
--- a/src/H5Smpio.c
+++ b/src/H5Smpio.c
@@ -106,7 +106,7 @@ H5S_mpio_all_type( const H5S_t *space, const size_t elmt_size,
/* fill in the return values */
*new_type = MPI_BYTE;
H5_CHECK_OVERFLOW(total_bytes, hsize_t, size_t);
- *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 15698fa..e5b64c1 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -3473,7 +3473,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);
}
@@ -7765,7 +7765,7 @@ H5T_array_create(H5T_t *base, int ndims, const hsize_t dim[/* ndims */],
{
H5T_t *ret_value = NULL; /*new array data type */
int i; /* local index variable */
-
+
FUNC_ENTER(H5T_array_create, NULL);
assert(base);
@@ -7787,8 +7787,8 @@ 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];
- ret_value->u.array.nelem *= dim[i];
+ H5_ASSIGN_OVERFLOW(ret_value->u.array.dim[i],dim[i],hsize_t,size_t);
+ ret_value->u.array.nelem *= (size_t)dim[i];
} /* end for */
/* Copy the dimension permutations */
@@ -8103,12 +8103,12 @@ H5T_debug(const 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 0157de9..4a63462 100644
--- a/src/H5TB.c
+++ b/src/H5TB.c
@@ -1154,13 +1154,15 @@ 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;
if (!HasChild(ptr, 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/H5Tconv.c b/src/H5Tconv.c
index d339266..b9b94e9 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -477,6 +477,8 @@ H5T_conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
H5T_t *dst = NULL;
#ifdef NO_DUFFS_DEVICE
hsize_t i;
+#else /* NO_DUFFS_DEVICE */
+ size_t duff_count;
#endif /* NO_DUFFS_DEVICE */
size_t j, md;
@@ -541,538 +543,532 @@ H5T_conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
buf_stride = buf_stride ? buf_stride : src->size;
/* Optimize for popular sizes */
- if(nelmts>0) {
- switch(md) {
- case 1: /* Swap 2-byte objects */
+ switch(md) {
+ case 1: /* Swap 2-byte objects */
#ifdef NO_DUFFS_DEVICE
- for (i=0; i<nelmts; i++, buf+=buf_stride) {
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- }
+ for (i=0; i<nelmts; i++, buf+=buf_stride) {
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ }
#else /* NO_DUFFS_DEVICE */
- {
- size_t duff_count = (nelmts + 7) / 8;
-
- switch ((long)(nelmts % 8))
- {
- case 0:
- do
- {
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 7:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 6:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 5:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 4:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 3:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 2:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- case 1:
- /* Swap the byte pair */
- tmp = buf[0];
- buf[0] = buf[1];
- buf[1] = tmp;
- buf+=buf_stride;
- }
- while (--duff_count > 0);
- }
- }
+ H5_CHECK_OVERFLOW(nelmts,hsize_t,size_t);
+ duff_count = ((size_t)nelmts + 7) / 8;
+
+ switch ((size_t)(nelmts % 8))
+ {
+ case 0:
+ do
+ {
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 7:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 6:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 5:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 4:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 3:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 2:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ case 1:
+ /* Swap the byte pair */
+ tmp = buf[0];
+ buf[0] = buf[1];
+ buf[1] = tmp;
+ buf+=buf_stride;
+ }
+ while (--duff_count > 0);
+ }
#endif /* NO_DUFFS_DEVICE */
- break;
+ break;
- case 2: /* Swap 4-byte objects */
+ case 2: /* Swap 4-byte objects */
#ifdef NO_DUFFS_DEVICE
- for (i=0; i<nelmts; i++, buf+=buf_stride) {
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
- }
+ for (i=0; i<nelmts; i++, buf+=buf_stride) {
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+ }
#else /* NO_DUFFS_DEVICE */
- {
- size_t duff_count = (nelmts + 7) / 8;
-
- switch ((long)(nelmts % 8))
- {
- case 0:
- do
- {
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 7:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 6:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 5:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 4:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 3:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 2:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 1:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[3];
- buf[3] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[1];
- buf[1] = buf[2];
- buf[2] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- }
- while (--duff_count > 0);
- }
- }
+ H5_CHECK_OVERFLOW(nelmts,hsize_t,size_t);
+ duff_count = ((size_t)nelmts + 7) / 8;
+
+ switch ((size_t)(nelmts % 8))
+ {
+ case 0:
+ do
+ {
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 7:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 6:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 5:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 4:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 3:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 2:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 1:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[3];
+ buf[3] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[2];
+ buf[2] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ }
+ while (--duff_count > 0);
+ }
#endif /* NO_DUFFS_DEVICE */
- break;
+ break;
- case 4: /* Swap 8-byte objects */
+ case 4: /* Swap 8-byte objects */
#ifdef NO_DUFFS_DEVICE
- for (i=0; i<nelmts; i++, buf+=buf_stride) {
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
- }
+ for (i=0; i<nelmts; i++, buf+=buf_stride) {
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+ }
#else /* NO_DUFFS_DEVICE */
- {
- size_t duff_count = (nelmts + 7) / 8;
-
- switch ((long)(nelmts % 8))
- {
- case 0:
- do
- {
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 7:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 6:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 5:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 4:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 3:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 2:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 1:
- /* Swap the outer pair of bytes */
- tmp = buf[0];
- buf[0] = buf[7];
- buf[7] = tmp;
-
- /* Swap the next-outer pair of bytes */
- tmp = buf[1];
- buf[1] = buf[6];
- buf[6] = tmp;
-
- /* Swap the next-next-outer pair of bytes */
- tmp = buf[2];
- buf[2] = buf[5];
- buf[5] = tmp;
-
- /* Swap the inner pair of bytes */
- tmp = buf[3];
- buf[3] = buf[4];
- buf[4] = tmp;
-
- /* Advance the pointer */
- buf+=buf_stride;
- }
- while (--duff_count > 0);
- }
- }
+ H5_CHECK_OVERFLOW(nelmts,hsize_t,size_t);
+ duff_count = ((size_t)nelmts + 7) / 8;
+
+ switch ((size_t)(nelmts % 8))
+ {
+ case 0:
+ do
+ {
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 7:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 6:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 5:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 4:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 3:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 2:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 1:
+ /* Swap the outer pair of bytes */
+ tmp = buf[0];
+ buf[0] = buf[7];
+ buf[7] = tmp;
+
+ /* Swap the next-outer pair of bytes */
+ tmp = buf[1];
+ buf[1] = buf[6];
+ buf[6] = tmp;
+
+ /* Swap the next-next-outer pair of bytes */
+ tmp = buf[2];
+ buf[2] = buf[5];
+ buf[5] = tmp;
+
+ /* Swap the inner pair of bytes */
+ tmp = buf[3];
+ buf[3] = buf[4];
+ buf[4] = tmp;
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ }
+ while (--duff_count > 0);
+ }
#endif /* NO_DUFFS_DEVICE */
- break;
+ break;
- default: /* Swap n-byte objects */
+ default: /* Swap n-byte objects */
#ifdef NO_DUFFS_DEVICE
- for (i=0; i<nelmts; i++, buf+=buf_stride) {
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
+ for (i=0; i<nelmts; i++, buf+=buf_stride) {
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
}
+ }
#else /* NO_DUFFS_DEVICE */
- {
- size_t duff_count = (nelmts + 7) / 8;
-
- switch ((long)(nelmts % 8))
- {
- case 0:
- do
- {
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 7:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 6:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 5:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 4:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 3:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 2:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- case 1:
- /* Generic byte-swapping loop */
- for (j=0; j<md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size-(j+1)];
- buf[src->size-(j+1)] = tmp;
- }
-
- /* Advance the pointer */
- buf+=buf_stride;
- }
- while (--duff_count > 0);
- }
- }
+ H5_CHECK_OVERFLOW(nelmts,hsize_t,size_t);
+ duff_count = ((size_t)nelmts + 7) / 8;
+
+ switch ((size_t)(nelmts % 8))
+ {
+ case 0:
+ do
+ {
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 7:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 6:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 5:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 4:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 3:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 2:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ case 1:
+ /* Generic byte-swapping loop */
+ for (j=0; j<md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size-(j+1)];
+ buf[src->size-(j+1)] = tmp;
+ }
+
+ /* Advance the pointer */
+ buf+=buf_stride;
+ }
+ while (--duff_count > 0);
+ }
#endif /* NO_DUFFS_DEVICE */
- break;
- } /* end switch */
- } /* end if */
+ break;
+ } /* end switch */
break;
case H5T_CONV_FREE:
@@ -1607,8 +1603,8 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
src_delta = src->size;
bkg_stride = dst->size;
} else {
- src_delta = -(src->size);
- bkg_stride = -(dst->size);
+ src_delta = -(int)src->size; /*overflow shouldn't be possible*/
+ bkg_stride = -(int)dst->size; /*overflow shouldn't be possible*/
xbuf += (nelmts-1) * src->size;
xbkg += (nelmts-1) * dst->size;
}
@@ -2469,8 +2465,9 @@ H5T_conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
/* Get length of sequences in bytes */
seq_len=(*(src->u.vlen.getlen))(src->u.vlen.f,s);
assert(seq_len>=0);
- src_size=seq_len*src_base_size;
- dst_size=seq_len*dst_base_size;
+ H5_CHECK_OVERFLOW(seq_len,hssize_t,size_t);
+ src_size=(size_t)seq_len*src_base_size;
+ dst_size=(size_t)seq_len*dst_base_size;
/* Check if conversion buffer is large enough, resize if
* necessary */
@@ -3301,7 +3298,8 @@ H5T_conv_f_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
* accomodate that value. The mantissa of course is no
* longer normalized.
*/
- mrsh += 1-expo;
+ H5_ASSIGN_OVERFLOW(mrsh,(mrsh+1-expo),hssize_t,size_t);
+ /*mrsh += 1-expo;*/
expo = 0;
} else if (expo>=expo_max) {
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c
index 2c305b7..0556078 100644
--- a/src/H5Tvlen.c
+++ b/src/H5Tvlen.c
@@ -208,7 +208,7 @@ herr_t H5T_vlen_seq_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo
H5MM_allocate_t alloc_func; /* Vlen allocation function */
void *alloc_info; /* Vlen allocation information */
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;
H5P_genplist_t *plist; /* Property list */
FUNC_ENTER (H5T_vlen_seq_mem_write, FAIL);
@@ -218,8 +218,9 @@ herr_t H5T_vlen_seq_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo
assert(buf);
if(seq_len!=0) {
+ H5_ASSIGN_OVERFLOW(len,(seq_len*base_size),hsize_t,size_t);
+
/* 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*/
/* Get the allocation function & info */
if(TRUE!=H5P_isa_class(plist_id,H5P_DATASET_XFER) || NULL == (plist = H5I_object(plist_id)))
@@ -230,11 +231,11 @@ herr_t H5T_vlen_seq_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo
HRETURN_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value");
if(alloc_func!=NULL) {
- if(NULL==(vl->p=(alloc_func)((size_t)(seq_len*base_size),alloc_info)))
+ if(NULL==(vl->p=(alloc_func)(len,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 */
@@ -246,7 +247,7 @@ herr_t H5T_vlen_seq_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo
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() */
@@ -331,16 +332,16 @@ herr_t H5T_vlen_str_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo
H5MM_allocate_t alloc_func; /* Vlen allocation function */
void *alloc_info; /* Vlen allocation information */
char **s=(char **)vl_addr; /* Pointer to the user's hvl_t information */
- size_t len=seq_len*base_size;
+ size_t len;
H5P_genplist_t *plist; /* Property list */
FUNC_ENTER (H5T_vlen_str_mem_write, FAIL);
/* check parameters */
assert(buf);
+ H5_CHECK_OVERFLOW(((seq_len+1)*base_size),hsize_t,size_t);
- /* 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*/
+ /* Use the user's memory allocation routine if one is defined */
/* Get the allocation function & info */
if(TRUE!=H5P_isa_class(plist_id,H5P_DATASET_XFER) || NULL == (plist = H5I_object(plist_id)))
@@ -359,6 +360,7 @@ herr_t H5T_vlen_str_mem_write(hid_t plist_id, H5F_t UNUSED *f, void *vl_addr, vo
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';
@@ -459,7 +461,7 @@ herr_t H5T_vlen_disk_write(hid_t UNUSED plist_id, H5F_t *f, void *vl_addr, 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);
@@ -469,11 +471,13 @@ herr_t H5T_vlen_disk_write(hid_t UNUSED plist_id, H5F_t *f, void *vl_addr, 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 c41f285..d4ac850 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);
HDmemcpy (dst, src, (size_t)elmt_size);
HRETURN (SUCCEED);
}