summaryrefslogtreecommitdiffstats
path: root/src/H5Oattr.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/H5Oattr.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/H5Oattr.c')
-rw-r--r--src/H5Oattr.c40
1 files changed, 14 insertions, 26 deletions
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 */