diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-07-28 03:51:43 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-07-28 03:51:43 (GMT) |
commit | d60d3679301d5587b077ae47eab091fdbb96a28d (patch) | |
tree | 4e9717e96ab1d43d157259dcb6200c5d260cb9ab | |
parent | ae0ae159563f4d284b4062f0c838f7c91d38f338 (diff) | |
download | hdf5-d60d3679301d5587b077ae47eab091fdbb96a28d.zip hdf5-d60d3679301d5587b077ae47eab091fdbb96a28d.tar.gz hdf5-d60d3679301d5587b077ae47eab091fdbb96a28d.tar.bz2 |
[svn-r8964] Purpose:
Revise new feature
Description:
Add buffer type and version # bytes to the encoded datatype and dataspace
buffers (for H5Tencode & H5Sencode)
Platforms tested:
FreeBSD 4.10 (sleipnir)
Too minor to require h5committest
-rw-r--r-- | src/H5S.c | 28 | ||||
-rw-r--r-- | src/H5T.c | 21 | ||||
-rw-r--r-- | test/dtypes.c | 11 | ||||
-rw-r--r-- | test/th5s.c | 6 |
4 files changed, 60 insertions, 6 deletions
@@ -32,6 +32,9 @@ #include "H5Oprivate.h" /* object headers */ #include "H5Spkg.h" /* Dataspace functions */ +/* Local macro definitions */ +#define H5S_ENCODE_VERSION 0 + /* Local static function prototypes */ static H5S_t * H5S_create(H5S_class_t type); static herr_t H5S_set_extent_simple (H5S_t *space, unsigned rank, @@ -1828,16 +1831,22 @@ H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) /* Verify the size of buffer. If it's not big enough, simply return the * right size without filling the buffer. */ - if(!buf || *nalloc<(extent_size+select_size+3)) { - *nalloc = extent_size+select_size+3; + if(!buf || *nalloc<(extent_size+select_size+1+1+1+4)) { + *nalloc = extent_size+select_size+1+1+1+4; HGOTO_DONE(ret_value); } + /* Encode the type of the information */ + *buf++ = H5O_SDSPACE_ID; + + /* Encode the version of the dataspace information */ + *buf++ = H5S_ENCODE_VERSION; + /* Encode the "size of size" information */ *buf++ = f.shared->sizeof_size; /* Encode size of extent information. Pointer is actually moved in this macro. */ - UINT16ENCODE(buf, extent_size); + UINT32ENCODE(buf, extent_size); /* Encode the extent part of dataspace */ if(H5O_encode(&f, buf, obj, H5O_SDSPACE_ID)<0) @@ -1926,6 +1935,17 @@ H5S_decode(unsigned char *buf) FUNC_ENTER_NOAPI(H5S_decode, NULL); + /* Initialize this before anything goes bad... */ + f.shared=NULL; + + /* Decode the type of the information */ + if(*buf++ != H5O_SDSPACE_ID) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADMESG, NULL, "not an encoded dataspace"); + + /* Decode the version of the dataspace information */ + if(*buf++ != H5S_ENCODE_VERSION) + HGOTO_ERROR(H5E_DATASPACE, H5E_VERSION, NULL, "unknown version of encoded dataspace"); + /* Fake file structure, used only for header message operation */ f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t)); @@ -1933,7 +1953,7 @@ H5S_decode(unsigned char *buf) f.shared->sizeof_size = *buf++; /* Decode size of extent information */ - UINT16DECODE(buf, extent_size); + UINT32DECODE(buf, extent_size); /* Decode the extent part of dataspace */ if((extent = H5O_decode(&f, buf, H5O_SDSPACE_ID))==NULL) @@ -259,6 +259,9 @@ static herr_t H5T_unregister(H5T_pers_t pers, const char *name, H5T_t *src, static herr_t H5T_register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_conv_t func, hid_t dxpl_id); +/* Local macro definitions */ +#define H5T_ENCODE_VERSION 0 + /* * Type initialization macros * @@ -2671,11 +2674,17 @@ H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc) HGOTO_ERROR(H5E_DATATYPE, H5E_BADSIZE, FAIL, "can't find datatype size"); /* Don't encode if buffer size isn't big enough or buffer is empty */ - if(!buf || *nalloc<buf_size) { - *nalloc = buf_size; + if(!buf || *nalloc<(buf_size+1+1)) { + *nalloc = buf_size+1+1; HGOTO_DONE(ret_value); } + /* Encode the type of the information */ + *buf++ = H5O_DTYPE_ID; + + /* Encode the version of the dataspace information */ + *buf++ = H5T_ENCODE_VERSION; + if(H5O_encode(&f, buf, obj, H5O_DTYPE_ID)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode object"); @@ -2709,6 +2718,14 @@ H5T_decode(unsigned char *buf) FUNC_ENTER_NOAPI(H5T_decode, NULL); + /* Decode the type of the information */ + if(*buf++ != H5O_DTYPE_ID) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADMESG, NULL, "not an encoded datatype"); + + /* Decode the version of the datatype information */ + if(*buf++ != H5T_ENCODE_VERSION) + HGOTO_ERROR(H5E_DATATYPE, H5E_VERSION, NULL, "unknown version of encoded datatype"); + if((ret_value = H5O_decode(NULL, buf, H5O_DTYPE_ID))==NULL) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, NULL, "can't decode object"); diff --git a/test/dtypes.c b/test/dtypes.c index e0fc7be..607b65a 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -1892,6 +1892,7 @@ test_encode(void) size_t cmpd_buf_size = 0; size_t enum_buf_size = 0; unsigned char *cmpd_buf=NULL, *enum_buf=NULL; + herr_t ret; TESTING("functions of encoding and decoding data types"); @@ -1977,6 +1978,16 @@ test_encode(void) if(cmpd_buf_size>0) cmpd_buf = (unsigned char*)calloc(1, cmpd_buf_size); + /* Try decoding bogus buffer */ + H5E_BEGIN_TRY { + ret = H5Tdecode(cmpd_buf); + } H5E_END_TRY; + if(ret!=FAIL) { + H5_FAILED(); + printf("Decoded bogus buffer!\n"); + goto error; + } + if(H5Tencode(tid1, cmpd_buf, &cmpd_buf_size)<0) { H5_FAILED(); printf("Can't encode compound type\n"); diff --git a/test/th5s.c b/test/th5s.c index c3724e2..9379413 100644 --- a/test/th5s.c +++ b/test/th5s.c @@ -563,6 +563,12 @@ test_h5s_encode(void) if(sbuf_size>0) sbuf = (unsigned char*)calloc(1, sbuf_size); + /* Try decoding bogus buffer */ + H5E_BEGIN_TRY { + ret = H5Sdecode(sbuf); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Sdecode"); + ret = H5Sencode(sid1, sbuf, &sbuf_size); CHECK(ret, FAIL, "H5Sencode"); |