From 1bca28acc3294e465d22e4dee8ecfc92fbc55ebe Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 9 Mar 2007 23:50:28 -0500 Subject: [svn-r13485] Description: Fix reference to uninitialized memory, which could trigger a memory corruption, once in a purple moon. Tested on: FreeBSD/32 6.2 (duty) w/valgrind --- src/H5Z.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/H5Z.c b/src/H5Z.c index a96e783..573ec6b 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -797,25 +797,25 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags, * filter struct is reallocated. Set these pointers to ~NULL * so that we can reset them after reallocating the filters array. */ - for(n=0; nnalloc; ++n) { + for(n = 0; n < pline->nalloc; ++n) if(pline->filter[n].cd_values == pline->filter[n]._cd_values) pline->filter[n].cd_values = (void *) ~((size_t)NULL); - } x.nalloc = MAX(H5Z_MAX_NFILTERS, 2 * pline->nalloc); - x.filter = H5MM_realloc(pline->filter, x.nalloc*sizeof(x.filter[0])); + x.filter = H5MM_realloc(pline->filter, x.nalloc * sizeof(x.filter[0])); if(NULL == x.filter) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter pipeline") - pline->nalloc = x.nalloc; - pline->filter = x.filter; - /* Fix pointers in filters that need to point to their own internal - * data. + /* Fix pointers in previous filters that need to point to their own + * internal data. */ - for(n=0; nnalloc; ++n) { - if(pline->filter[n].cd_values == (void *) ~((size_t) NULL)) - pline->filter[n].cd_values = pline->filter[n]._cd_values; - } + for(n = 0; n < pline->nalloc; ++n) + if(x.filter[n].cd_values == (void *) ~((size_t) NULL)) + x.filter[n].cd_values = x.filter[n]._cd_values; + + /* Point to newly allocated buffer */ + pline->nalloc = x.nalloc; + pline->filter = x.filter; } /* end if */ /* Add the new filter to the pipeline */ -- cgit v0.12