summaryrefslogtreecommitdiffstats
path: root/src/H5A.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2001-11-27 16:29:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2001-11-27 16:29:13 (GMT)
commitd456c2bb82be98bc2b7c1039927eb52258d1a0eb (patch)
treea7d8a65aef5d962c89b0965c86eb535917c023ad /src/H5A.c
parent05264c88788f9bd9b04a58673ded246904210235 (diff)
downloadhdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.zip
hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.tar.gz
hdf5-d456c2bb82be98bc2b7c1039927eb52258d1a0eb.tar.bz2
[svn-r4643] Purpose:
Code cleanup Description: Windows is generating hundreds of warnings from some of the practices in the library. Mostly, they are because size_t is 32-bit and hsize_t is 64-bit on Windows and we were carelessly casting the larger values down to the smaller ones without checking for overflow. Also, some other small code cleanups,etc. Solution: Re-worked some algorithms to eliminate the casts and also added more overflow checking for assignments and function parameters which needed casts. Kent did most of the work, I just went over his changes and fit them into the the library code a bit better. Platforms tested: FreeBSD 4.4 (hawkwind)
Diffstat (limited to 'src/H5A.c')
-rw-r--r--src/H5A.c74
1 files changed, 25 insertions, 49 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));