summaryrefslogtreecommitdiffstats
path: root/src/H5Tvlen.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/H5Tvlen.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/H5Tvlen.c')
-rw-r--r--src/H5Tvlen.c22
1 files changed, 13 insertions, 9 deletions
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 */