summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c170
1 files changed, 135 insertions, 35 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 9320d28..2758395 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -1,3 +1,4 @@
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
@@ -67,10 +68,6 @@
*
*/
-/* Define the code template for types which need no extra initialization for the "GUTS" in the H5T_INIT_TYPE macro */
-#define H5T_INIT_TYPE_NONE_CORE { \
-}
-
/* Define the code template for bitfields for the "GUTS" in the H5T_INIT_TYPE macro */
#define H5T_INIT_TYPE_BITFIELD_CORE { \
dt->shared->type = H5T_BITFIELD; \
@@ -1986,7 +1983,7 @@ H5T_detect_class(const H5T_t *dt, H5T_class_t cls, hbool_t from_api)
case H5T_VLEN:
case H5T_ENUM:
HGOTO_DONE(H5T_detect_class(dt->shared->parent, cls, from_api));
-
+ break;
case H5T_NO_CLASS:
case H5T_INTEGER:
case H5T_FLOAT:
@@ -3211,7 +3208,7 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method)
switch(new_dt->shared->type) {
case H5T_COMPOUND:
{
- int accum_change = 0; /* Amount of change in the offset of the fields */
+ ssize_t accum_change = 0; /* Amount of change in the offset of the fields */
/*
* Copy all member fields to new type, then overwrite the
@@ -3239,13 +3236,17 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method)
new_dt->shared->u.compnd.memb[i].type = tmp;
HDassert(tmp != NULL);
+ /* Range check against compound member's offset */
+ if ((accum_change < 0) && ((ssize_t) new_dt->shared->u.compnd.memb[i].offset < accum_change))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, NULL, "invalid field size in datatype");
+
/* Apply the accumulated size change to the offset of the field */
- new_dt->shared->u.compnd.memb[i].offset += accum_change;
+ new_dt->shared->u.compnd.memb[i].offset += (size_t) accum_change;
if(old_dt->shared->u.compnd.sorted != H5T_SORT_VALUE) {
for(old_match = -1, j = 0; j < old_dt->shared->u.compnd.nmembs; j++) {
if(!HDstrcmp(new_dt->shared->u.compnd.memb[i].name, old_dt->shared->u.compnd.memb[j].name)) {
- old_match = j;
+ old_match = (int) j;
break;
} /* end if */
} /* end for */
@@ -3255,20 +3256,23 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "fields in datatype corrupted");
} /* end if */
else
- old_match = i;
+ old_match = (int) i;
/* If the field changed size, add that change to the accumulated size change */
if(new_dt->shared->u.compnd.memb[i].type->shared->size != old_dt->shared->u.compnd.memb[old_match].type->shared->size) {
/* Adjust the size of the member */
new_dt->shared->u.compnd.memb[i].size = (old_dt->shared->u.compnd.memb[old_match].size*tmp->shared->size)/old_dt->shared->u.compnd.memb[old_match].type->shared->size;
- accum_change += (new_dt->shared->u.compnd.memb[i].type->shared->size - old_dt->shared->u.compnd.memb[old_match].type->shared->size);
+ accum_change += (ssize_t) (new_dt->shared->u.compnd.memb[i].type->shared->size - old_dt->shared->u.compnd.memb[old_match].type->shared->size);
} /* end if */
} /* end for */
- /* Apply the accumulated size change to the size of the compound struct */
- new_dt->shared->size += accum_change;
+ /* Range check against datatype size */
+ if ((accum_change < 0) && ((ssize_t) new_dt->shared->size < accum_change))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, NULL, "invalid field size in datatype");
+ /* Apply the accumulated size change to the size of the compound struct */
+ new_dt->shared->size += (size_t) accum_change;
}
break;
@@ -3313,6 +3317,13 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method)
new_dt->shared->size=new_dt->shared->u.array.nelem*new_dt->shared->parent->shared->size;
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_NCLASSES:
default:
break;
} /* end switch */
@@ -3530,6 +3541,16 @@ H5T__free(H5T_t *dt)
H5MM_xfree(dt->shared->u.opaque.tag);
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_REFERENCE:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
break;
} /* end switch */
@@ -3796,11 +3817,14 @@ H5T_set_size(H5T_t *dt, size_t size)
case H5T_ARRAY:
case H5T_REFERENCE:
HDassert("can't happen" && 0);
+ break;
case H5T_NO_CLASS:
case H5T_NCLASSES:
HDassert("invalid type" && 0);
+ break;
default:
HDassert("not implemented yet" && 0);
+ break;
}
/* Commit (if we didn't convert this type to a VL string) */
@@ -3875,7 +3899,6 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
unsigned *idx1 = NULL, *idx2 = NULL;
size_t base_size;
hbool_t swapped;
- int i, j;
unsigned u;
int tmp;
int ret_value = 0;
@@ -3930,24 +3953,32 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
for(u = 0; u < dt1->shared->u.compnd.nmembs; u++)
idx1[u] = idx2[u] = u;
if(dt1->shared->u.enumer.nmembs > 1) {
- for(i = dt1->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i)
+ int i;
+
+ for(i = (int) dt1->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i) {
+ int j;
+
for(j = 0, swapped=FALSE; j < i; j++)
if(HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name,
dt1->shared->u.compnd.memb[idx1[j + 1]].name) > 0) {
- tmp = idx1[j];
+ unsigned tmp_idx = idx1[j];
idx1[j] = idx1[j + 1];
- idx1[j + 1] = tmp;
+ idx1[j + 1] = tmp_idx;
swapped = TRUE;
}
- for(i = dt2->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i)
+ }
+ for(i = (int) dt2->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i) {
+ int j;
+
for(j = 0, swapped = FALSE; j<i; j++)
if(HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name,
dt2->shared->u.compnd.memb[idx2[j + 1]].name) > 0) {
- tmp = idx2[j];
+ unsigned tmp_idx = idx2[j];
idx2[j] = idx2[j + 1];
- idx2[j + 1] = tmp;
+ idx2[j + 1] = tmp_idx;
swapped = TRUE;
}
+ }
} /* end if */
#ifdef H5T_DEBUG
@@ -4007,28 +4038,39 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed");
for (u=0; u<dt1->shared->u.enumer.nmembs; u++)
idx1[u] = u;
- if(dt1->shared->u.enumer.nmembs > 1)
- for (i=dt1->shared->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i)
- for (j=0, swapped=FALSE; j<i; j++)
+ if(dt1->shared->u.enumer.nmembs > 1) {
+ int i;
+ for (i = (int) dt1->shared->u.enumer.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i) {
+ int j;
+
+ for (j = 0, swapped = FALSE; j < i; j++)
if (HDstrcmp(dt1->shared->u.enumer.name[idx1[j]],
dt1->shared->u.enumer.name[idx1[j+1]]) > 0) {
- tmp = idx1[j];
+ unsigned tmp_idx = idx1[j];
idx1[j] = idx1[j+1];
- idx1[j+1] = tmp;
+ idx1[j+1] = tmp_idx;
swapped = TRUE;
}
+ }
+ }
for (u=0; u<dt2->shared->u.enumer.nmembs; u++)
idx2[u] = u;
- if(dt2->shared->u.enumer.nmembs > 1)
- for (i=dt2->shared->u.enumer.nmembs-1, swapped=TRUE; swapped && i>=0; --i)
- for (j=0, swapped=FALSE; j<i; j++)
+ if(dt2->shared->u.enumer.nmembs > 1) {
+ int i;
+
+ for (i = (int) dt2->shared->u.enumer.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i) {
+ int j;
+
+ for (j = 0, swapped = FALSE; j < i; j++)
if (HDstrcmp(dt2->shared->u.enumer.name[idx2[j]],
dt2->shared->u.enumer.name[idx2[j+1]]) > 0) {
- tmp = idx2[j];
+ unsigned tmp_idx = idx2[j];
idx2[j] = idx2[j+1];
- idx2[j+1] = tmp;
+ idx2[j+1] = tmp_idx;
swapped = TRUE;
}
+ }
+ }
#ifdef H5T_DEBUG
/* I don't quite trust the code above yet :-) --RPM */
@@ -4148,6 +4190,14 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
HGOTO_DONE(1);
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_REFERENCE:
+ case H5T_NCLASSES:
default:
/*
* Atomic datatypes...
@@ -4255,13 +4305,23 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
case H5R_BADTYPE:
case H5R_MAXTYPE:
HDassert("invalid type" && 0);
+ break;
default:
HDassert("not implemented yet" && 0);
+ break;
}
break;
+ case H5T_NO_CLASS:
+ case H5T_OPAQUE:
+ case H5T_COMPOUND:
+ case H5T_ENUM:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
HDassert("not implemented yet" && 0);
+ break;
}
break;
} /* end switch */
@@ -4535,7 +4595,7 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
} /* end if */
if(cmp > 0)
md++;
- HDmemmove(H5T_g.path + md + 1, H5T_g.path + md, (H5T_g.npaths - md) * sizeof(H5T_path_t*));
+ HDmemmove(H5T_g.path + md + 1, H5T_g.path + md, (size_t) (H5T_g.npaths - md) * sizeof(H5T_path_t*));
H5T_g.npaths++;
H5T_g.path[md] = path;
table = path;
@@ -5000,6 +5060,17 @@ H5T_is_sensible(const H5T_t *dt)
ret_value=FALSE;
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_REFERENCE:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
/* Assume all other datatype are sensible to store on disk */
ret_value=TRUE;
@@ -5041,7 +5112,6 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc)
htri_t changed; /* Whether H5T_set_loc changed the type (even if the size didn't change) */
htri_t ret_value = 0; /* Indicate that success, but no location change */
unsigned i; /* Local index variable */
- int accum_change; /* Amount of change in the offset of the fields */
size_t old_size; /* Previous size of a field */
FUNC_ENTER_NOAPI(FAIL)
@@ -5075,14 +5145,21 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc)
break;
case H5T_COMPOUND: /* Check each field and recurse on VL, compound and array type */
+ {
+ ssize_t accum_change = 0; /* Amount of change in the offset of the fields */
+
/* Sort the fields based on offsets */
H5T__sort_value(dt, NULL);
- for (i=0,accum_change=0; i<dt->shared->u.compnd.nmembs; i++) {
+ for (i=0; i<dt->shared->u.compnd.nmembs; i++) {
H5T_t *memb_type; /* Member's datatype pointer */
+ /* Range check against compound member's offset */
+ if ((accum_change < 0) && ((ssize_t) dt->shared->u.compnd.memb[i].offset < accum_change))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype");
+
/* Apply the accumulated size change to the offset of the field */
- dt->shared->u.compnd.memb[i].offset += accum_change;
+ dt->shared->u.compnd.memb[i].offset += (size_t) accum_change;
/* Set the member type pointer (for convenience) */
memb_type=dt->shared->u.compnd.memb[i].type;
@@ -5105,13 +5182,18 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc)
dt->shared->u.compnd.memb[i].size = (dt->shared->u.compnd.memb[i].size*memb_type->shared->size)/old_size;
/* Add that change to the accumulated size change */
- accum_change += (memb_type->shared->size - (int)old_size);
+ accum_change += (ssize_t) (memb_type->shared->size - old_size);
} /* end if */
} /* end if */
} /* end for */
+ /* Range check against datatype size */
+ if ((accum_change < 0) && ((ssize_t) dt->shared->size < accum_change))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype");
+
/* Apply the accumulated size change to the datatype */
- dt->shared->size = (size_t)(dt->shared->size + accum_change);
+ dt->shared->size += (size_t) accum_change;
+ }
break;
case H5T_VLEN: /* Recurse on the VL information if it's VL, compound or array, then free VL sequence */
@@ -5145,6 +5227,15 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc)
} /* end if */
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_ENUM:
+ case H5T_NCLASSES:
default:
break;
} /* end switch */
@@ -5235,6 +5326,15 @@ H5T_upgrade_version_cb(H5T_t *dt, void *op_value)
dt->shared->version = dt->shared->parent->shared->version;
break;
+ case H5T_NO_CLASS:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_REFERENCE:
+ case H5T_NCLASSES:
default:
break;
} /* end switch */