summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2001-12-11 18:26:40 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2001-12-11 18:26:40 (GMT)
commit3baaa562ee650b7c5062c747cab425cd80ab53e0 (patch)
treed90e869acae6fb2cf001bf3a50d224dd50e7f7ef
parent43c1f21316556ae6ac898061a49194270d7e9d8b (diff)
downloadhdf5-3baaa562ee650b7c5062c747cab425cd80ab53e0.zip
hdf5-3baaa562ee650b7c5062c747cab425cd80ab53e0.tar.gz
hdf5-3baaa562ee650b7c5062c747cab425cd80ab53e0.tar.bz2
[svn-r4693] Purpose:
Bug Fix Description: The code in H5Sselect_hyperslab_valid contained an fencepost error and is allowing selections which overlap the extent by exactly one element in any dimension to pass as valid instead of flagging the selection as invalid. This bug only affects hyperslabs which have been OR'ed together, not the selection from a single H5Sselect_hyperslab. This fixes bug #550. Solution: Changed an '>' to an '>=' and added new regression test to check for error. Platforms tested: FreeBSD 4.4 (sleipnir)
-rw-r--r--release_docs/RELEASE.txt3
-rw-r--r--src/H5Shyper.c4
-rw-r--r--test/tselect.c97
3 files changed, 102 insertions, 2 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index c5bce70..09be12f 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -90,6 +90,9 @@ Library
properly if they caused close() to fail.
* Fixed a bug in internal B-tree code where a B-tree was not being copied
correctly.
+ * Fixed an off-by-one error in H5Sselect_valid when hyperslab selections
+ which would allow hyperslab selections which overlapped the edge of the
+ selection by one element as valid.
Configuration
-------------
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index 809f7e3..8be16e9 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -4994,9 +4994,9 @@ H5S_hyper_select_valid_helper (const H5S_hyper_span_info_t *spans, const hssize_
while(curr!=NULL && ret_value==TRUE) {
/* Check if an offset has been defined */
/* Bounds check the selected point + offset against the extent */
- if(((curr->low+offset[rank])>(hssize_t)size[rank])
+ if(((curr->low+offset[rank])>=(hssize_t)size[rank])
|| ((curr->low+offset[rank])<0)
- || ((curr->high+offset[rank])>(hssize_t)size[rank])
+ || ((curr->high+offset[rank])>=(hssize_t)size[rank])
|| ((curr->high+offset[rank])<0)) {
ret_value=FALSE;
break;
diff --git a/test/tselect.c b/test/tselect.c
index c5aa682..6a413bd 100644
--- a/test/tselect.c
+++ b/test/tselect.c
@@ -3703,6 +3703,101 @@ test_select_hyper_chunk(hid_t fapl_plist, hid_t xfer_plist)
/****************************************************************
**
+** test_select_valid(): Test basic H5S (dataspace) selection code.
+** Tests selection validity
+**
+****************************************************************/
+static void
+test_select_valid(void)
+{
+ herr_t error;
+ htri_t valid;
+ hid_t main_space, sub_space;
+ hssize_t safe_start[2]={1,1};
+ hsize_t safe_count[2]={1,1};
+ hssize_t start[2];
+ hsize_t dims[2],maxdims[2],size[2],count[2];
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Selection Validity\n"));
+
+ count[0] = count[1] = 1;
+ dims[0] = dims[1] = maxdims[0] = maxdims[1] = 10;
+
+ main_space = H5Screate_simple(2,dims,maxdims);
+ CHECK(main_space, FAIL, "H5Screate_simple");
+
+ MESSAGE(8, ( "Case 1 : in the dimensions\nTry offset (4,4) and size(6,6), the original space is of size (10,10)\n"));
+ start[0] = start[1] = 4;
+ size[0] = size[1] = 6;
+
+ sub_space = H5Scopy(main_space);
+ CHECK(sub_space, FAIL, "H5Scopy");
+
+ error=H5Sselect_hyperslab(sub_space,H5S_SELECT_SET,start,size,count,size);
+ CHECK(error, FAIL, "H5Sselect_hyperslab");
+
+ valid=H5Sselect_valid(sub_space);
+ VERIFY(valid, TRUE, "H5Sselect_valid");
+
+ error=H5Sselect_hyperslab(sub_space,H5S_SELECT_OR,safe_start,NULL,safe_count,NULL);
+ CHECK(error, FAIL, "H5Sselect_hyperslab");
+
+ valid=H5Sselect_valid(sub_space);
+ VERIFY(valid, TRUE, "H5Sselect_valid");
+
+ error=H5Sclose(sub_space);
+ CHECK(error, FAIL, "H5Sclose");
+
+ MESSAGE(8, ( "Case 2 : exceed dimensions by 1\nTry offset (5,5) and size(6,6), the original space is of size (10,10)\n"));
+ start[0] = start[1] = 5;
+ size[0] = size[1] = 6;
+
+ sub_space = H5Scopy(main_space);
+ CHECK(sub_space, FAIL, "H5Scopy");
+
+ error=H5Sselect_hyperslab(sub_space,H5S_SELECT_SET,start,size,count,size);
+ CHECK(error, FAIL, "H5Sselect_hyperslab");
+
+ valid=H5Sselect_valid(sub_space);
+ VERIFY(valid, FALSE, "H5Sselect_valid");
+
+ error=H5Sselect_hyperslab(sub_space,H5S_SELECT_OR,safe_start,NULL,safe_count,NULL);
+ CHECK(error, FAIL, "H5Sselect_hyperslab");
+
+ valid=H5Sselect_valid(sub_space);
+ VERIFY(valid, FALSE, "H5Sselect_valid");
+
+ error=H5Sclose(sub_space);
+ CHECK(error, FAIL, "H5Sclose");
+
+ MESSAGE(8, ( "Case 3 : exceed dimensions by 2\nTry offset (6,6) and size(6,6), the original space is of size (10,10)\n"));
+ start[0] = start[1] = 6;
+ size[0] = size[1] = 6;
+
+ sub_space = H5Scopy(main_space);
+ CHECK(sub_space, FAIL, "H5Scopy");
+
+ error=H5Sselect_hyperslab(sub_space,H5S_SELECT_SET,start,size,count,size);
+ CHECK(error, FAIL, "H5Sselect_hyperslab");
+
+ valid=H5Sselect_valid(sub_space);
+ VERIFY(valid, FALSE, "H5Sselect_valid");
+
+ error=H5Sselect_hyperslab(sub_space,H5S_SELECT_OR,safe_start,NULL,safe_count,NULL);
+ CHECK(error, FAIL, "H5Sselect_hyperslab");
+
+ valid=H5Sselect_valid(sub_space);
+ VERIFY(valid, FALSE, "H5Sselect_valid");
+
+ error=H5Sclose(sub_space);
+ CHECK(error, FAIL, "H5Sclose");
+ error=H5Sclose(main_space);
+ CHECK(error, FAIL, "H5Sclose");
+} /* test_select_hyper_chunk() */
+
+/****************************************************************
+**
** test_select(): Main H5S selection testing routine.
**
****************************************************************/
@@ -3795,6 +3890,8 @@ test_select(void)
ret=H5Pclose(plist_id);
CHECK(ret, FAIL, "H5Pclose");
+ /* More tests for checking validity of selections */
+ test_select_valid();
} /* test_select() */