diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2001-11-27 16:29:13 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2001-11-27 16:29:13 (GMT) |
commit | d456c2bb82be98bc2b7c1039927eb52258d1a0eb (patch) | |
tree | a7d8a65aef5d962c89b0965c86eb535917c023ad /src/H5R.c | |
parent | 05264c88788f9bd9b04a58673ded246904210235 (diff) | |
download | hdf5-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/H5R.c')
-rw-r--r-- | src/H5R.c | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -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; |