diff options
author | Jerome Soumagne <jsoumagne@hdfgroup.org> | 2015-05-04 19:32:53 (GMT) |
---|---|---|
committer | Jerome Soumagne <jsoumagne@hdfgroup.org> | 2015-05-04 19:32:53 (GMT) |
commit | 77dc445a3d3d037255aaf13f6c55053c41621f74 (patch) | |
tree | 2fc3bd1e04d03a22982b63b0a6444295667bf6ba | |
parent | e5a1bf1fb13bc96b73740b8ab34334b3c042fcee (diff) | |
download | hdf5-77dc445a3d3d037255aaf13f6c55053c41621f74.zip hdf5-77dc445a3d3d037255aaf13f6c55053c41621f74.tar.gz hdf5-77dc445a3d3d037255aaf13f6c55053c41621f74.tar.bz2 |
[svn-r27008] Bring H5T warning fixes from trunk
Includes r26848/r26868/r26907
-rw-r--r-- | src/H5T.c | 170 |
1 files changed, 135 insertions, 35 deletions
@@ -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; \ @@ -2000,7 +1997,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: @@ -3225,7 +3222,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 @@ -3253,13 +3250,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 */ @@ -3269,20 +3270,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; @@ -3327,6 +3331,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 */ @@ -3544,6 +3555,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 */ @@ -3810,11 +3831,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) */ @@ -3889,7 +3913,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; @@ -3944,24 +3967,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 @@ -4021,28 +4052,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 */ @@ -4162,6 +4204,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... @@ -4269,13 +4319,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 */ @@ -4549,7 +4609,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; @@ -5014,6 +5074,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; @@ -5055,7 +5126,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) @@ -5089,14 +5159,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; @@ -5119,13 +5196,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 */ @@ -5159,6 +5241,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 */ @@ -5249,6 +5340,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 */ |