summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2018-03-18 23:36:49 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2018-03-18 23:36:49 (GMT)
commitf38864920d4e0bc8adaf9a23fd3f775ad90cb3f7 (patch)
treeb5f709e5415db2f1a9287b43565fea826b3018f5 /src/H5T.c
parent4a17aff4085ad6ee265b95730aca3f493056dec8 (diff)
parent7aa4eb1b04014f1ad7e1c857ca6509aeeb6c0ae7 (diff)
downloadhdf5-f38864920d4e0bc8adaf9a23fd3f775ad90cb3f7.zip
hdf5-f38864920d4e0bc8adaf9a23fd3f775ad90cb3f7.tar.gz
hdf5-f38864920d4e0bc8adaf9a23fd3f775ad90cb3f7.tar.bz2
Merge branch 'develop' of https://bitbucket.hdfgroup.org/scm/hdffv/hdf5 into merge_func_enter_vol
Plus initial steps toward merging API context push into FUNC_ENTER_API* macros
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/H5T.c b/src/H5T.c
index d4d67f1..bb046fa 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -516,6 +516,12 @@ double H5T_NATIVE_DOUBLE_NEG_INF_g = (double)0.0f;
H5FL_DEFINE(H5T_t);
H5FL_DEFINE(H5T_shared_t);
+/* Format version bounds for datatype */
+const unsigned H5O_dtype_ver_bounds[] = {
+ H5O_DTYPE_VERSION_1, /* H5F_LIBVER_EARLIEST */
+ H5O_DTYPE_VERSION_3, /* H5F_LIBVER_V18 */
+ H5O_DTYPE_VERSION_LATEST /* H5F_LIBVER_LATEST */
+};
/*******************/
/* Local Variables */
@@ -545,6 +551,7 @@ static const H5I_class_t H5I_DATATYPE_CLS[1] = {{
(H5I_free_t)H5T__close_cb /* Callback routine for closing objects of this class */
}};
+
/* Flag indicating "top" of interface has been initialized */
static hbool_t H5T_top_package_initialize_s = FALSE;
@@ -2933,8 +2940,13 @@ H5Tdecode(const void *buf)
if(buf == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "empty buffer")
- /* Create datatype by decoding buffer */
- if(NULL == (dt = H5T_decode((const unsigned char *)buf)))
+ /* Create datatype by decoding buffer
+ * There is no way to get the size of the buffer, so we pass in
+ * SIZE_MAX and assume the caller knows what they are doing.
+ * Really fixing this will require an H5Tdecode2() call that
+ * takes a size parameter.
+ */
+ if(NULL == (dt = H5T_decode(SIZE_MAX, (const unsigned char *)buf)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "can't decode object")
/* Register the type and return the ID */
@@ -3023,7 +3035,7 @@ done:
*-------------------------------------------------------------------------
*/
H5T_t *
-H5T_decode(const unsigned char *buf)
+H5T_decode(size_t buf_size, const unsigned char *buf)
{
H5F_t *f = NULL; /* Fake file structure*/
H5T_t *ret_value = NULL; /* Return value */
@@ -3043,7 +3055,7 @@ H5T_decode(const unsigned char *buf)
HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype")
/* Decode the serialized datatype message */
- if(NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf)))
+ if(NULL == (ret_value = (H5T_t *)H5O_msg_decode(f, NULL, H5O_DTYPE_ID, buf_size, buf)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object")
/* Mark datatype as being in memory now */
@@ -5419,6 +5431,11 @@ H5T_set_loc(H5T_t *dt, H5F_t *f, H5T_loc_t loc)
/* Check if the field changed size */
if(old_size != memb_type->shared->size) {
+
+ /* Fail if the old_size is zero */
+ if (0 == old_size)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "old_size of zero would cause division by zero");
+
/* Adjust the size of the member */
dt->shared->u.compnd.memb[i].size = (dt->shared->u.compnd.memb[i].size*memb_type->shared->size)/old_size;
@@ -5618,34 +5635,44 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5T_set_latest_version
+ * Function: H5T_set_version
*
- * Purpose: Set the encoding for a datatype to the latest version.
+ * Purpose: Set the encoding for a datatype to the version indicated by
+ * the file's low bound if that is higher than the datatype's
+ * version.
*
* Return: Non-negative on success/Negative on failure
*
- * Programmer: Quincey Koziol
- * Thursday, July 19, 2007
+ * Programmer: Vailin Choi; December 2017
*
*-------------------------------------------------------------------------
*/
herr_t
-H5T_set_latest_version(H5T_t *dt)
+H5T_set_version(H5F_t *f, H5T_t *dt)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned vers; /* The version */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
+ HDassert(f);
HDassert(dt);
- /* Upgrade the format version for the datatype to the latest */
- if(H5T__upgrade_version(dt, H5O_DTYPE_VERSION_LATEST) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't upgrade datatype encoding")
+ vers = H5O_dtype_ver_bounds[H5F_LOW_BOUND(f)];
+ if(vers > dt->shared->version) {
+ /* Upgrade the format version for the datatype */
+ if(H5T__upgrade_version(dt, vers) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't upgrade datatype encoding")
+ }
+
+ /* Version bounds check */
+ if(dt->shared->version > H5O_dtype_ver_bounds[H5F_HIGH_BOUND(f)])
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADRANGE, FAIL, "Datatype version out of bounds")
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5T_set_latest_version() */
+} /* end H5T_set_version() */
/*-------------------------------------------------------------------------