From ae6956a76362d619f41318c19792a4e0c7b9d529 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Tue, 5 Oct 2004 14:17:09 -0500 Subject: [svn-r9367] Purpose: feature change Description: Prevent create datatype of size 0 Platforms tested: heping(simple change) --- src/H5T.c | 6 ++++-- test/dtypes.c | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/H5T.c b/src/H5T.c index 033feed..5c41803 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -1356,8 +1356,8 @@ H5Tcreate(H5T_class_t type, size_t size) FUNC_ENTER_API(H5Tcreate, FAIL); H5TRACE2("i","Ttz",type,size); - /* check args. We start to support size adjustment for compound type. */ - if (size == 0 && type != H5T_COMPOUND) + /* check args */ + if (size == 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid size"); /* create the type */ @@ -1960,6 +1960,8 @@ H5Tset_size(hid_t type_id, size_t size) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined"); if (H5T_REFERENCE==dt->shared->type) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype"); + if (size==0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't adjust size to 0"); /* Do the work */ if (H5T_set_size(dt, size)<0) diff --git a/test/dtypes.c b/test/dtypes.c index 83e41ad..53b53ea 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -2063,38 +2063,47 @@ test_compound_12(void) TESTING("adjust size of compound data types"); /* Create the empty compound type */ - if ((complex_id = H5Tcreate(H5T_COMPOUND, 0))<0) goto error; + if ((complex_id = H5Tcreate(H5T_COMPOUND, 1))<0) goto error; + + /* Verify the size */ + if((new_size=H5Tget_size(complex_id))==0) goto error; + if(new_size!=1) goto error; /* Add a couple fields and adjust the size */ offset = size; - if((size+=H5Tget_size(H5T_NATIVE_DOUBLE))<0) goto error; + size+=H5Tget_size(H5T_NATIVE_DOUBLE); if (H5Tset_size(complex_id, size)<0) goto error; if (H5Tinsert(complex_id, "real", offset, H5T_NATIVE_DOUBLE)<0) goto error; offset = size; - if((size+=H5Tget_size(H5T_NATIVE_DOUBLE))<0) goto error; + size+=H5Tget_size(H5T_NATIVE_DOUBLE); if (H5Tset_size(complex_id, size)<0) goto error; if (H5Tinsert(complex_id, "imaginary", offset, H5T_NATIVE_DOUBLE)<0) goto error; /* Increase and decrease the size. */ - if((size+=H5Tget_size(H5T_NATIVE_DOUBLE))<0) goto error; + size+=H5Tget_size(H5T_NATIVE_DOUBLE); if (H5Tset_size(complex_id, size)<0) goto error; - if((size-=H5Tget_size(H5T_NATIVE_DOUBLE))<0) goto error; + size-=H5Tget_size(H5T_NATIVE_DOUBLE); if (H5Tset_size(complex_id, size)<0) goto error; /* Verify the size */ - if((new_size=H5Tget_size(complex_id))<0) goto error; + if((new_size=H5Tget_size(complex_id))==0) goto error; if(new_size!=size) goto error; /* Tries to cut last member. Supposed to fail. */ size--; H5E_BEGIN_TRY { - H5Tset_size(complex_id, size); + ret = H5Tset_size(complex_id, size); } H5E_END_TRY; - + if(ret>=0) { + H5_FAILED(); + puts(" Tries to cut off the last member. Should have failed."); + goto error; + } + if (H5Tclose (complex_id)<0) goto error; PASSED(); return 0; -- cgit v0.12