summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2009-01-27 15:56:48 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2009-01-27 15:56:48 (GMT)
commitbf4789092a2a63d8418677e66410a7cbee665fa5 (patch)
tree859103103d2d56da3dcc3cdfc6bdb8d26c601c45
parenta6dcbd6a0ffbc17179b83e0910aca3e78b9b706a (diff)
downloadhdf5-bf4789092a2a63d8418677e66410a7cbee665fa5.zip
hdf5-bf4789092a2a63d8418677e66410a7cbee665fa5.tar.gz
hdf5-bf4789092a2a63d8418677e66410a7cbee665fa5.tar.bz2
[svn-r16360] Purpose: Fix potential error with H5Tset_order
Description: H5Tset_order will now properly reject H5T_ORDER_NONE for most datatypes. Previously this could cause major problems as the file could not be flushed. Tested: jam, smirom (h5committest)
-rw-r--r--release_docs/RELEASE.txt2
-rw-r--r--src/H5Torder.c2
-rw-r--r--test/dtypes.c167
3 files changed, 171 insertions, 0 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index 230cb8c..4e35418 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -141,6 +141,8 @@ Bug Fixes since HDF5-1.8.0 release
Library
-------
+ - Changed H5Tset_order to properly reject H5T_ORDER_NONE for most
+ datatypes. (NAF - 2009/01/27)
- Fixed a bug where H5Tpack wouldn't remove trailing space from an
otherwise packed compound type. (NAF - 2009/01/14)
- Fixed up some old v2 btree assertions that get run in debug mode that
diff --git a/src/H5Torder.c b/src/H5Torder.c
index 34dbd8e..6c0667b 100644
--- a/src/H5Torder.c
+++ b/src/H5Torder.c
@@ -158,6 +158,8 @@ H5Tset_order(hid_t type_id, H5T_order_t order)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
while (dt->shared->parent)
dt = dt->shared->parent; /*defer to parent*/
+ if (order == H5T_ORDER_NONE && !(H5T_REFERENCE == dt->shared->type || H5T_IS_FIXED_STRING(dt->shared)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order")
if (!H5T_IS_ATOMIC(dt->shared))
HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified datatype")
diff --git a/test/dtypes.c b/test/dtypes.c
index 3aad1a7..991b2c9 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -5644,6 +5644,172 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_set_order
+ *
+ * Purpose: Tests H5Tset_order/H5Tget_order. Verifies that
+ * H5T_ORDER_NONE cannot be set.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Neil Fortner
+ * January 23, 2009
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_set_order(void)
+{
+ hid_t dtype; /* Datatype ID */
+ H5T_order_t order; /* Byte order */
+ hsize_t dims[2] = {3, 4}; /* Array dimenstions */
+ herr_t ret; /* Generic return value */
+
+ TESTING("H5Tset/get_order");
+
+ /* Integer */
+ if ((dtype = H5Tcopy(H5T_STD_I32BE)) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Float */
+ if ((dtype = H5Tcopy(H5T_IEEE_F64LE)) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Time */
+ if ((dtype = H5Tcopy(H5T_UNIX_D64BE)) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Fixed length string */
+ if ((dtype = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
+ if (H5Tset_size(dtype, 5) < 0) TEST_ERROR
+ if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR;
+ if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
+
+ /* Variable length string */
+ if (H5Tset_size(dtype, H5T_VARIABLE) < 0) TEST_ERROR
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Bitfield */
+ if ((dtype = H5Tcopy(H5T_STD_B16LE)) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Opaque - functions should fail */
+ if ((dtype = H5Tcreate(H5T_OPAQUE, 96)) < 0) TEST_ERROR
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_LE);
+ order = H5Tget_order(dtype);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (order >= 0) TEST_ERROR
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Compound - functions should fail */
+ if ((dtype = H5Tcreate(H5T_COMPOUND, 48)) < 0) TEST_ERROR
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_LE);
+ order = H5Tget_order(dtype);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (order >= 0) TEST_ERROR
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Object reference */
+ if ((dtype = H5Tcopy(H5T_STD_REF_OBJ)) < 0) TEST_ERROR
+ if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR;
+ if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Region reference */
+ if ((dtype = H5Tcopy(H5T_STD_REF_DSETREG)) < 0) TEST_ERROR
+ if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR;
+ if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Enum */
+ if ((dtype = H5Tenum_create(H5T_STD_I16BE)) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Vlen */
+ if ((dtype = H5Tvlen_create(H5T_STD_U64LE)) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ /* Array */
+ if ((dtype = H5Tarray_create2(H5T_IEEE_F64BE, 2, dims)) < 0) TEST_ERROR
+ if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
+ H5E_BEGIN_TRY
+ ret = H5Tset_order(dtype, H5T_ORDER_NONE);
+ H5E_END_TRY
+ if (ret >= 0) TEST_ERROR
+ if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
+ if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
+ if (H5Tclose(dtype) < 0) TEST_ERROR
+
+ PASSED();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY
+ H5Tclose (dtype);
+ H5E_END_TRY;
+ return 1;
+} /* end test_set_order() */
+
+
+/*-------------------------------------------------------------------------
* Function: test_deprec
*
* Purpose: Tests deprecated API routines for datatypes.
@@ -5846,6 +6012,7 @@ main(void)
nerrors += test_conv_bitfield();
nerrors += test_bitfield_funcs();
nerrors += test_opaque();
+ nerrors += test_set_order();
if(nerrors) {
printf("***** %lu FAILURE%s! *****\n",