diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2009-10-28 03:00:50 (GMT) |
---|---|---|
committer | Neil Fortner <nfortne2@hdfgroup.org> | 2009-10-28 03:00:50 (GMT) |
commit | 0599c6f0a436a42768b0ca0ed3701833cc25fb88 (patch) | |
tree | 1c03f8e438e0cec5f70980cdfe875f263c32243a /src/H5HG.c | |
parent | f6ebbc01094db95c4455e2cb1c3a77ccd0ee9c6f (diff) | |
download | hdf5-0599c6f0a436a42768b0ca0ed3701833cc25fb88.zip hdf5-0599c6f0a436a42768b0ca0ed3701833cc25fb88.tar.gz hdf5-0599c6f0a436a42768b0ca0ed3701833cc25fb88.tar.bz2 |
[svn-r17766] Purpose: Fix bug 1483
Description:
H5HG_load made improper assumptions about the ordering of object indices, namely
that they are in order. Not only is this not guaranteed by the file format
spec, but this condition can be violated if id's "wrap around" which can happen
when overwriting VL data. H5HG_load has been fixed to handle any order of
indices. Also fixed some other bugs involving allocation of global heaps in
memory.
Tested: jam, linew, amani (h5committest)
Diffstat (limited to 'src/H5HG.c')
-rw-r--r-- | src/H5HG.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -311,7 +311,7 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size, unsigned * heap_flags_ptr) * Find an ID for the new object. ID zero is reserved for the free space * object. */ - if(heap->nused<H5HG_MAXIDX) + if(heap->nused<=H5HG_MAXIDX) idx=heap->nused++; else { for (idx=1; idx<heap->nused; idx++) @@ -327,17 +327,21 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size, unsigned * heap_flags_ptr) H5HG_obj_t *new_obj; /* New array of object descriptions */ /* Determine the new number of objects to index */ - new_alloc=MAX(heap->nalloc*2,(idx+1)); - assert(new_alloc<=(H5HG_MAXIDX+1)); + /* nalloc is *not* guaranteed to be a power of 2! - NAF 10/26/09 */ + new_alloc = MIN(MAX(heap->nalloc * 2, (idx + 1)), (H5HG_MAXIDX + 1)); + HDassert(idx < new_alloc); /* Reallocate array of objects */ if (NULL==(new_obj = H5FL_SEQ_REALLOC (H5HG_obj_t, heap->obj, new_alloc))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed") + /* Clear newly allocated space */ + HDmemset(&new_obj[heap->nalloc], 0, (new_alloc - heap->nalloc) * sizeof(heap->obj[0])); + /* Update heap information */ heap->nalloc=new_alloc; heap->obj=new_obj; - assert(heap->nalloc>heap->nused); + HDassert(heap->nalloc>heap->nused); } /* end if */ /* Initialize the new object */ |