summaryrefslogtreecommitdiffstats
path: root/src/H5Shyper.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-06-18 05:10:36 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-06-18 05:10:36 (GMT)
commit47bd0eecd65317c8ffbae0b403e0f412d6d17551 (patch)
treed58593770d4183bb52bc11e131cc7a540d6667e1 /src/H5Shyper.c
parentc5ec1ebfbc6ae66d1ddfafbe02c6b6a9d5a08cac (diff)
downloadhdf5-47bd0eecd65317c8ffbae0b403e0f412d6d17551.zip
hdf5-47bd0eecd65317c8ffbae0b403e0f412d6d17551.tar.gz
hdf5-47bd0eecd65317c8ffbae0b403e0f412d6d17551.tar.bz2
[svn-r10952] Purpose:
Bug fix Description: Hyperslab selections that had a selection offset and were applied to a chunked dataset could get into an infinite loop or core dump if the same selection was used multiple times, with different selection offsets. Solution: "Normalize" the selection with the selection offset, generate the selections for the chunks overlapped and then "denormalize" the selection. Platforms tested: FreeBSD 4.11 (sleipnir) Too minor to require h5committest
Diffstat (limited to 'src/H5Shyper.c')
-rw-r--r--src/H5Shyper.c78
1 files changed, 63 insertions, 15 deletions
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index 9360432..f3b5d22 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -3667,7 +3667,7 @@ done:
REVISION LOG
--------------------------------------------------------------------------*/
static htri_t
-H5S_hyper_intersect_block_helper (const H5S_hyper_span_info_t *spans, hssize_t *offset, hsize_t *start, hsize_t *end)
+H5S_hyper_intersect_block_helper (const H5S_hyper_span_info_t *spans, hsize_t *start, hsize_t *end)
{
H5S_hyper_span_t *curr; /* Pointer to current span in 1st span tree */
htri_t status; /* Status from recursive call */
@@ -3677,7 +3677,6 @@ H5S_hyper_intersect_block_helper (const H5S_hyper_span_info_t *spans, hssize_t *
/* Sanity check */
assert(spans);
- assert(offset);
assert(start);
assert(end);
@@ -3687,11 +3686,11 @@ H5S_hyper_intersect_block_helper (const H5S_hyper_span_info_t *spans, hssize_t *
/* Iterate over the spans in the tree */
while(curr!=NULL) {
/* Check for span entirely before block */
- if(((hssize_t)curr->high+*offset)<(hssize_t)*start)
+ if(curr->high < *start)
/* Advance to next span in this dimension */
curr=curr->next;
/* If this span is past the end of the block, then we're done in this dimension */
- else if(((hssize_t)curr->low+*offset)>(hssize_t)*end)
+ else if(curr->low > *end)
HGOTO_DONE(FALSE)
/* block & span overlap */
else {
@@ -3699,7 +3698,7 @@ H5S_hyper_intersect_block_helper (const H5S_hyper_span_info_t *spans, hssize_t *
HGOTO_DONE(TRUE)
else {
/* Recursively check spans in next dimension down */
- if((status=H5S_hyper_intersect_block_helper(curr->down,offset+1,start+1,end+1))<0)
+ if((status=H5S_hyper_intersect_block_helper(curr->down,start+1,end+1))<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab intersection check");
/* If there is a span intersection in the down dimensions, the span trees overlap */
@@ -3759,7 +3758,7 @@ H5S_hyper_intersect_block (H5S_t *space, hsize_t *start, hsize_t *end)
HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree");
/* Perform the span-by-span intersection check */
- if((ret_value=H5S_hyper_intersect_block_helper(space->select.sel_info.hslab->span_lst,space->select.offset,start,end))<0)
+ if((ret_value=H5S_hyper_intersect_block_helper(space->select.sel_info.hslab->span_lst,start,end))<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab intersection check");
done:
@@ -4102,20 +4101,22 @@ done:
"Normalize" a hyperslab selection by adjusting it's coordinates by the
amount of the selection offset.
USAGE
- herr_t H5S_hyper_normalize_offset(space)
+ herr_t H5S_hyper_normalize_offset(space, old_offset)
H5S_t *space; IN/OUT: Pointer to dataspace to move
+ hssize_t *old_offset; OUT: Pointer to space to store old offset
RETURNS
Non-negative on success, negative on failure
DESCRIPTION
- Moves the hyperslab selection by the selection offset and then resets
- the selection offset to zeros.
+ Copies the current selection offset into the array provided, then
+ inverts the selection offset, subtracts the offset from the hyperslab
+ selection and resets the offset to zero.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
-H5S_hyper_normalize_offset(H5S_t *space)
+H5S_hyper_normalize_offset(H5S_t *space, hssize_t *old_offset)
{
unsigned u; /* Local index variable */
herr_t ret_value=SUCCEED; /* Return value */
@@ -4127,17 +4128,18 @@ H5S_hyper_normalize_offset(H5S_t *space)
/* Check for 'all' selection, instead of a hyperslab selection */
/* (Technically, this check shouldn't be in the "hyperslab" routines...) */
if(H5S_GET_SELECT_TYPE(space)!=H5S_SEL_ALL) {
- /* Invert the selection offset */
- for(u=0; u<space->extent.rank; u++)
- space->select.offset[u] =- space->select.offset[u];
+ /* Copy & invert the selection offset */
+ for(u=0; u<space->extent.rank; u++) {
+ old_offset[u] = space->select.offset[u];
+ space->select.offset[u] = -space->select.offset[u];
+ } /* end for */
/* Call the existing 'adjust' routine */
if(H5S_hyper_adjust_s(space, space->select.offset)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab normalization");
/* Zero out the selection offset */
- for(u=0; u<space->extent.rank; u++)
- space->select.offset[u] = 0;
+ HDmemset(space->select.offset, 0, sizeof(hssize_t) * space->extent.rank);
} /* end if */
done:
@@ -4147,6 +4149,52 @@ done:
/*--------------------------------------------------------------------------
NAME
+ H5S_hyper_denormalize_offset
+ PURPOSE
+ "Denormalize" a hyperslab selection by reverse adjusting it's coordinates
+ by the amount of the former selection offset.
+ USAGE
+ herr_t H5S_hyper_normalize_offset(space, old_offset)
+ H5S_t *space; IN/OUT: Pointer to dataspace to move
+ hssize_t *old_offset; IN: Pointer to old offset array
+ RETURNS
+ Non-negative on success, negative on failure
+ DESCRIPTION
+ Subtracts the old offset from the current selection (canceling out the
+ effect of the "normalize" routine), then restores the old offset into
+ the dataspace.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+herr_t
+H5S_hyper_denormalize_offset(H5S_t *space, const hssize_t *old_offset)
+{
+ herr_t ret_value=SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_denormalize_offset);
+
+ assert(space);
+
+ /* Check for 'all' selection, instead of a hyperslab selection */
+ /* (Technically, this check shouldn't be in the "hyperslab" routines...) */
+ if(H5S_GET_SELECT_TYPE(space)!=H5S_SEL_ALL) {
+ /* Call the existing 'adjust' routine */
+ if(H5S_hyper_adjust_s(space, old_offset)<0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab normalization");
+
+ /* Copy the selection offset over */
+ HDmemcpy(space->select.offset, old_offset, sizeof(hssize_t) * space->extent.rank);
+ } /* end if */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* H5S_hyper_denormalize_offset() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
H5S_hyper_append_span
PURPOSE
Create a new span and append to span list