From c61a0a3d6200c6513cc49c4fe5cb05e0313e571a Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Wed, 26 Oct 2011 09:25:16 -0500 Subject: [svn-r21674] Issue 7618 - the library had seg fault when it tried to shrink the size of compound data type through H5Tset_size immedia tely after the type was created. I fixed it in this commit. Tested on jam, linew, and koala. --- release_docs/RELEASE.txt | 3 +++ src/H5T.c | 24 +++++++++++++----------- test/dtypes.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 18e4924..8b0ff7a 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -343,6 +343,9 @@ Bug Fixes since HDF5-1.8.0 release Library ------- + - The library had seg fault when it tried to shrink the size of compound type + through H5Tset_size immediately after the type was created (Issue + 7618). It's fixed now. (SLU - 2011/10/26) - Fixed a bug that occurred when using H5Ocopy on a committed datatype containing an attribute using that committed datatype. (NAF - 2011/10/13 - Issue 5854) diff --git a/src/H5T.c b/src/H5T.c index ed54051..2519a8f 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3712,7 +3712,7 @@ H5T_set_size(H5T_t *dt, size_t size) case H5T_COMPOUND: /* If decreasing size, check the last member isn't being cut. */ if(sizeshared->size) { - int num_membs; + int num_membs = 0; unsigned i, max_index=0; size_t memb_offset, max_offset=0; size_t max_size; @@ -3720,18 +3720,20 @@ H5T_set_size(H5T_t *dt, size_t size) if((num_membs = H5T_get_nmembers(dt))<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to get number of members"); - for(i=0; i<(unsigned)num_membs; i++) { - memb_offset = H5T_get_member_offset(dt, i); - if(memb_offset > max_offset) { - max_offset = memb_offset; - max_index = i; - } - } + if(num_membs) { + for(i=0; i<(unsigned)num_membs; i++) { + memb_offset = H5T_get_member_offset(dt, i); + if(memb_offset > max_offset) { + max_offset = memb_offset; + max_index = i; + } + } - max_size = H5T_get_member_size(dt, max_index); + max_size = H5T_get_member_size(dt, max_index); - if(size<(max_offset+max_size)) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size shrinking will cut off last member "); + if(size<(max_offset+max_size)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "size shrinking will cut off last member "); + } /* Compound must not have been packed previously */ /* We will check if resizing changed the packed state of diff --git a/test/dtypes.c b/test/dtypes.c index 7138823..e0d1f8f 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -523,6 +523,12 @@ test_compound_1(void) if ((complex_id = H5Tcreate(H5T_COMPOUND, sizeof(complex_t))) < 0) goto error; + /* Try to shrink and expand the size */ + if(H5Tset_size(complex_id, sizeof(double)) < 0) + goto error; + if(H5Tset_size(complex_id, sizeof(complex_t)) < 0) + goto error; + /* Attempt to add the new compound datatype as a field within itself */ H5E_BEGIN_TRY { ret=H5Tinsert(complex_id, "compound", (size_t)0, complex_id); @@ -538,6 +544,14 @@ test_compound_1(void) goto error; /* Test some functions that aren't supposed to work for compound type */ + /* Tries to shrink the size and trail the last member */ + H5E_BEGIN_TRY { + ret=H5Tset_size(complex_id, sizeof(double)); + } H5E_END_TRY; + if (ret>=0) { + FAIL_PUTS_ERROR("Operation not allowed for this type."); + } /* end if */ + H5E_BEGIN_TRY { size=H5Tget_precision(complex_id); } H5E_END_TRY; -- cgit v0.12