Skip to content

Commit 293b777

Browse files
committed
Fix assertion failure in H5S__copy_pnt_list()
1 parent 3448276 commit 293b777

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/H5Spoint.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -800,12 +800,15 @@ H5S__copy_pnt_list(const H5S_pnt_list_t *src, unsigned rank)
800800

801801
/* Sanity checks */
802802
assert(src);
803-
assert(rank > 0);
804803

805804
/* Allocate room for the head of the point list */
806805
if (NULL == (dst = H5FL_CALLOC(H5S_pnt_list_t)))
807806
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate point list node");
808807

808+
/* If source dataspace has no extent, just return new point list node */
809+
if (rank == 0)
810+
HGOTO_DONE(dst);
811+
809812
curr = src->head;
810813
new_tail = NULL;
811814
while (curr) {

test/th5s.c

+38-3
Original file line numberDiff line numberDiff line change
@@ -3360,10 +3360,10 @@ test_h5s_bug3(void)
33603360
hid_t space3 = H5I_INVALID_HID;
33613361

33623362
space1 = H5Screate_simple(1, dims, NULL);
3363-
CHECK(space1, FAIL, "H5Screate_simple");
3363+
CHECK(space1, H5I_INVALID_HID, "H5Screate_simple");
33643364

33653365
space2 = H5Screate_simple(1, dims, NULL);
3366-
CHECK(space2, FAIL, "H5Screate_simple");
3366+
CHECK(space2, H5I_INVALID_HID, "H5Screate_simple");
33673367

33683368
/* Select a single, different element in each dataspace */
33693369
start[0] = 0;
@@ -3382,7 +3382,7 @@ test_h5s_bug3(void)
33823382
* wasn't a hyperslab.
33833383
*/
33843384
space3 = H5Scombine_select(space1, H5S_SELECT_AND, space2);
3385-
CHECK(space3, FAIL, "H5Scombine_select");
3385+
CHECK(space3, H5I_INVALID_HID, "H5Scombine_select");
33863386

33873387
/* Close dataspaces */
33883388
ret = H5Sclose(space1);
@@ -3393,6 +3393,40 @@ test_h5s_bug3(void)
33933393
CHECK(ret, FAIL, "H5Sclose");
33943394
} /* test_h5s_bug3() */
33953395

3396+
/****************************************************************
3397+
**
3398+
** test_h5s_bug4(): Test copying a dataspace with a point
3399+
** selection after the dataspace's extent has
3400+
** been reset with H5Sset_extent_none().
3401+
**
3402+
****************************************************************/
3403+
static void
3404+
test_h5s_bug4(void)
3405+
{
3406+
hsize_t dims[] = {10};
3407+
hsize_t points[] = {0};
3408+
herr_t ret = SUCCEED;
3409+
hid_t space_id = H5I_INVALID_HID;
3410+
hid_t space_copy_id = H5I_INVALID_HID;
3411+
3412+
space_id = H5Screate_simple(1, dims, NULL);
3413+
CHECK(space_id, H5I_INVALID_HID, "H5Screate_simple");
3414+
3415+
ret = H5Sselect_elements(space_id, H5S_SELECT_SET, 1, points);
3416+
CHECK(ret, FAIL, "H5Sselect_elements");
3417+
3418+
ret = H5Sset_extent_none(space_id);
3419+
CHECK(ret, FAIL, "H5Sselect_elements");
3420+
3421+
space_copy_id = H5Scopy(space_id);
3422+
CHECK(space_id, H5I_INVALID_HID, "H5Screate_simple");
3423+
3424+
ret = H5Sclose(space_copy_id);
3425+
CHECK(ret, FAIL, "H5Sclose");
3426+
ret = H5Sclose(space_id);
3427+
CHECK(ret, FAIL, "H5Sclose");
3428+
} /* test_h5s_bug4() */
3429+
33963430
/*-------------------------------------------------------------------------
33973431
* Function: test_versionbounds
33983432
*
@@ -3577,6 +3611,7 @@ test_h5s(void H5_ATTR_UNUSED *params)
35773611
test_h5s_bug1(); /* Test bug in offset initialization */
35783612
test_h5s_bug2(); /* Test bug found in H5S__hyper_update_diminfo() */
35793613
test_h5s_bug3(); /* Test bug found in H5S__combine_select() */
3614+
test_h5s_bug4(); /* Test bug in point selection copying */
35803615
test_versionbounds(); /* Test version bounds with dataspace */
35813616
} /* test_h5s() */
35823617

0 commit comments

Comments
 (0)