summaryrefslogtreecommitdiffstats
path: root/src/H5Shyper.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-02-15 03:23:19 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-02-15 03:23:19 (GMT)
commitc5c0afaa613115284c4d564a574a13b97027c1ab (patch)
tree98561ce374f7bd333ede4dc721c291fc2b597ea4 /src/H5Shyper.c
parent824d691cbf1a04e3207218e86246645b5609079e (diff)
downloadhdf5-c5c0afaa613115284c4d564a574a13b97027c1ab.zip
hdf5-c5c0afaa613115284c4d564a574a13b97027c1ab.tar.gz
hdf5-c5c0afaa613115284c4d564a574a13b97027c1ab.tar.bz2
[svn-r18256] Description:
Bring changes from Coverity fixing branch to trunk: r18235: Fixed coverity 114: if (NULL ==_dest) H5MM_free(dest); r18236: Close Coverity issue #28 (again :-) by working through the logic of the routine more thoroughly to eliminate the goto statements. (LK & QK) r18237: fixed coverity 133: if (NULL==_dest && NULL==ret_value && NULL != dest) H5MM_free(dest); r18238: Fix coverity items 421 and 422. Added assertion that the heap's free list is NULL when entering H5HL_fl_deserialize, guarateeing that the free list will always be linked in even on failure. r18239: Fix coverity item 268. Changed H5MM_xfree(read_buf) to read_buf = H5MM_xfree(read_buf) so that read_buf isn't manipulated after it's been freed. r18241: coverity fix: use correct free functon H5FL_FREE()from the previous fix r18242: Coverity fix 139: Free dst correctly in H5O_sdspace_copy(). r18243: Fix Coverity issue #417 by checking for NULL return value from setup_cache() (LK & QK) r18244: Coverity Fix 132: free dest correctly in H5O_efl_copy() r18245: Issue 121: H5S_hyper_make_spans() cannot deal with counts of 0. However, H5Sselect_hyperslab() API does allow a count of 0. Therefore, simply throw an error if this function encounters a count of 0. r18246: Check file_ptr to address coverity issue # 418 r18247: Fixed coverity 113: if (sequence) H5MM_xfree(sequence); r18248: Coverity issue #414 by checking for NULL return from setup_cache() (LK & QK) r18249: fixed coverity 274: moved H5FL_FREE(H5A_t, attr); to a line above so that if attr is null, it will not free it. r18250: Fix coverity issue #86. Check return of malloc function to ensure non-null before continuing. Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production) (h5committested in daily tests on branch)
Diffstat (limited to 'src/H5Shyper.c')
-rw-r--r--src/H5Shyper.c119
1 files changed, 56 insertions, 63 deletions
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index ea37e40..0565cf3 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -5421,17 +5421,17 @@ H5S_hyper_spans_nelem (H5S_hyper_span_info_t *spans)
REVISION LOG
--------------------------------------------------------------------------*/
static H5S_hyper_span_info_t *
-H5S_hyper_make_spans (unsigned rank, const hsize_t *start, const hsize_t *stride,
+H5S_hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride,
const hsize_t *count, const hsize_t *block)
{
- H5S_hyper_span_info_t *down; /* Pointer to spans in next dimension down */
- H5S_hyper_span_t *span; /* New hyperslab span */
- H5S_hyper_span_t *last_span; /* Current position in hyperslab span list */
- H5S_hyper_span_t *head; /* Head of new hyperslab span list */
- hsize_t stride_iter; /* Iterator over the stride values */
- int i; /* Counters */
- unsigned u; /* Counters */
- H5S_hyper_span_info_t *ret_value = NULL;
+ H5S_hyper_span_info_t *down; /* Pointer to spans in next dimension down */
+ H5S_hyper_span_t *span; /* New hyperslab span */
+ H5S_hyper_span_t *last_span; /* Current position in hyperslab span list */
+ H5S_hyper_span_t *head; /* Head of new hyperslab span list */
+ hsize_t stride_iter; /* Iterator over the stride values */
+ int i; /* Counters */
+ unsigned u; /* Counters */
+ H5S_hyper_span_info_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_make_spans);
@@ -5446,21 +5446,23 @@ H5S_hyper_make_spans (unsigned rank, const hsize_t *start, const hsize_t *stride
down = NULL;
for(i = (rank - 1); i >= 0; i--) {
+ /* Sanity check */
+ if(0 == count[i])
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, NULL, "count == 0 is invalid")
+
/* Start a new list in this dimension */
head = NULL;
last_span = NULL;
- HDassert(count[i] > 0);
-
/* Generate all the span segments for this dimension */
for(u = 0, stride_iter = 0; u < count[i]; u++, stride_iter += stride[i]) {
/* Allocate a span node */
if(NULL == (span = H5FL_MALLOC(H5S_hyper_span_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate hyperslab span")
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span")
/* Set the span's basic information */
span->low = start[i] + stride_iter;
- span->high = span->low + (block[i]-1);
+ span->high = span->low + (block[i] - 1);
span->nelem = block[i];
span->pstride = stride[i];
span->next = NULL;
@@ -5486,7 +5488,7 @@ H5S_hyper_make_spans (unsigned rank, const hsize_t *start, const hsize_t *stride
/* Allocate a span info node */
if(NULL == (down = H5FL_MALLOC(H5S_hyper_span_info_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate hyperslab span");
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span")
/* Set the reference count */
down->count = 0;
@@ -5515,13 +5517,13 @@ done:
do {
if(down) {
head = down->head;
- (void)H5FL_FREE(H5S_hyper_span_info_t, down);
+ down = H5FL_FREE(H5S_hyper_span_info_t, down);
} /* end if */
down = head->down;
while(head) {
last_span = head->next;
- (void)H5FL_FREE(H5S_hyper_span_t, head);
+ head = H5FL_FREE(H5S_hyper_span_t, head);
head = last_span;
} /* end while */
} while(down);
@@ -7376,74 +7378,70 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter,
/* Advance the hyperslab iterator */
/* Check if we are done */
- if(io_bytes_left>0) {
+ if(io_bytes_left > 0) {
/* Move to next span in fastest changing dimension */
- curr_span=curr_span->next;
+ curr_span = curr_span->next;
- if(curr_span!=NULL) {
+ if(NULL != curr_span) {
/* Move location offset of destination */
- loc_off+=(curr_span->low-abs_arr[fast_dim])*elem_size;
+ loc_off += (curr_span->low - abs_arr[fast_dim]) * elem_size;
/* Move iterator for fastest changing dimension */
- abs_arr[fast_dim]=curr_span->low;
+ abs_arr[fast_dim] = curr_span->low;
} /* end if */
} /* end if */
else {
- abs_arr[fast_dim]+=span_size/elem_size;
+ abs_arr[fast_dim] += span_size / elem_size;
/* Check if we are still within the span */
- if(abs_arr[fast_dim]<=curr_span->high) {
- iter->u.hyp.span[fast_dim]=curr_span;
-
- goto partial_done; /* finished with partial span */
+ if(abs_arr[fast_dim] <= curr_span->high) {
+ iter->u.hyp.span[fast_dim] = curr_span;
} /* end if */
/* If we walked off that span, advance to the next span */
else {
/* Advance span in this dimension */
- curr_span=curr_span->next;
+ curr_span = curr_span->next;
/* Check if we have a valid span in this dimension still */
- if(curr_span!=NULL) {
+ if(NULL != curr_span) {
/* Reset absolute position */
- abs_arr[fast_dim]=curr_span->low;
- iter->u.hyp.span[fast_dim]=curr_span;
-
- goto partial_done; /* finished with partial span */
+ abs_arr[fast_dim] = curr_span->low;
+ iter->u.hyp.span[fast_dim] = curr_span;
} /* end if */
} /* end else */
} /* end else */
/* Adjust iterator pointers */
- if(curr_span==NULL) {
+ if(NULL == curr_span) {
/* Same as code in main loop */
/* Start at the next fastest dim */
- curr_dim=fast_dim-1;
+ curr_dim = fast_dim - 1;
/* Work back up through the dimensions */
- while(curr_dim>=0) {
+ while(curr_dim >= 0) {
/* Reset the current span */
- curr_span=iter->u.hyp.span[curr_dim];
+ curr_span = iter->u.hyp.span[curr_dim];
/* Increment absolute position */
abs_arr[curr_dim]++;
/* Check if we are still within the span */
- if(abs_arr[curr_dim]<=curr_span->high) {
+ if(abs_arr[curr_dim] <= curr_span->high) {
break;
} /* end if */
/* If we walked off that span, advance to the next span */
else {
/* Advance span in this dimension */
- curr_span=curr_span->next;
+ curr_span = curr_span->next;
/* Check if we have a valid span in this dimension still */
- if(curr_span!=NULL) {
+ if(NULL != curr_span) {
/* Reset the span in the current dimension */
- ispan[curr_dim]=curr_span;
+ ispan[curr_dim] = curr_span;
/* Reset absolute position */
- abs_arr[curr_dim]=curr_span->low;
+ abs_arr[curr_dim] = curr_span->low;
break;
} /* end if */
@@ -7454,45 +7452,40 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter,
} /* end else */
} /* end while */
- /* Check if we are finished with the spans in the tree */
- if(curr_dim<0) {
- /* We had better be done with I/O or bad things are going to happen... */
- assert(io_bytes_left==0);
-
- goto partial_done; /* finished with partial span */
- } /* end if */
- else {
+ /* Check if we have more spans in the tree */
+ if(curr_dim >= 0) {
/* Walk back down the iterator positions, reseting them */
- while(curr_dim<fast_dim) {
- assert(curr_span);
- assert(curr_span->down);
- assert(curr_span->down->head);
+ while(curr_dim < fast_dim) {
+ HDassert(curr_span);
+ HDassert(curr_span->down);
+ HDassert(curr_span->down->head);
/* Increment current dimension */
curr_dim++;
/* Set the new span_info & span for this dimension */
- iter->u.hyp.span[curr_dim]=curr_span->down->head;
+ iter->u.hyp.span[curr_dim] = curr_span->down->head;
/* Advance span down the tree */
- curr_span=curr_span->down->head;
+ curr_span = curr_span->down->head;
/* Reset the absolute offset for the dim */
- abs_arr[curr_dim]=curr_span->low;
+ abs_arr[curr_dim] = curr_span->low;
} /* end while */
/* Verify that the curr_span points to the fastest dim */
- assert(curr_span==iter->u.hyp.span[fast_dim]);
- } /* end else */
+ HDassert(curr_span == iter->u.hyp.span[fast_dim]);
- /* Reset the buffer offset */
- for(i=0, loc_off=0; i<ndims; i++)
- loc_off+=(abs_arr[i]+off_arr[i])*slab[i];
+ /* Reset the buffer offset */
+ for(i = 0, loc_off = 0; i < ndims; i++)
+ loc_off += (abs_arr[i] + off_arr[i]) * slab[i];
+ } /* end else */
+ else
+ /* We had better be done with I/O or bad things are going to happen... */
+ HDassert(io_bytes_left == 0);
} /* end if */
} /* end if */
-partial_done: /* Yes, goto's are evil, so sue me... :-) */
-
/* Perform the I/O on the elements, based on the position of the iterator */
while(io_bytes_left > 0 && curr_seq < maxseq) {
/* Sanity check */