summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-10-26 14:25:16 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-10-26 14:25:16 (GMT)
commitc61a0a3d6200c6513cc49c4fe5cb05e0313e571a (patch)
tree97e7e3a640ac87219dd90a787021a768938aed21 /src/H5T.c
parent9b7016e1d76779c9b5ba459a8eb41006d373766a (diff)
downloadhdf5-c61a0a3d6200c6513cc49c4fe5cb05e0313e571a.zip
hdf5-c61a0a3d6200c6513cc49c4fe5cb05e0313e571a.tar.gz
hdf5-c61a0a3d6200c6513cc49c4fe5cb05e0313e571a.tar.bz2
[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.
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c24
1 files changed, 13 insertions, 11 deletions
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(size<dt->shared->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