diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2019-11-18 17:53:50 (GMT) |
---|---|---|
committer | Neil Fortner <nfortne2@hdfgroup.org> | 2019-11-18 17:53:50 (GMT) |
commit | 4064332a2dc45e591666ce1bff02001239009bb8 (patch) | |
tree | 746f10086a14edbcbc76990e64cef77113d53c70 /src/H5Sselect.c | |
parent | 3593b3d201dd6eac4a71e67db02a54959d9a169e (diff) | |
download | hdf5-4064332a2dc45e591666ce1bff02001239009bb8.zip hdf5-4064332a2dc45e591666ce1bff02001239009bb8.tar.gz hdf5-4064332a2dc45e591666ce1bff02001239009bb8.tar.bz2 |
Replace H5Sselect_adjust_u() and H5Shyper_adjust_s() with
H5Sselect_adjust. Implement "adjust_s" callback for all selection
types. Add range checking to H5Sselect_adjust().
Diffstat (limited to 'src/H5Sselect.c')
-rw-r--r-- | src/H5Sselect.c | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 65a66cb..70d971e 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -971,9 +971,59 @@ H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_adjust_u() */ + +/*-------------------------------------------------------------------------- + NAME + H5S_select_adjust_s + PURPOSE + Adjust a selection by subtracting an offset + USAGE + herr_t H5S_select_adjust_u(space, offset) + H5S_t *space; IN/OUT: Pointer to dataspace to adjust + const hssize_t *offset; IN: Offset to subtract + RETURNS + Non-negative on success, negative on failure + DESCRIPTION + Moves a selection by subtracting an offset from it. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + This routine participates in the "Inlining C function pointers" + pattern, don't call it directly, use the appropriate macro + defined in H5Sprivate.h. + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5S_select_adjust_s(H5S_t *space, const hssize_t *offset) +{ + hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Check args */ + HDassert(space); + HDassert(offset); + + /* Check for an all-zero offset vector */ + for(u = 0; u < space->extent.rank; u++) + if(0 != offset[u]) { + non_zero_offset = TRUE; + break; + } /* end if */ + + /* Only perform operation if the offset is non-zero */ + if(non_zero_offset) + ret_value = (*space->select.type->adjust_s)(space, offset); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S_select_adjust_s() */ + + /*-------------------------------------------------------------------------- NAME - H5Sselect_adjust_u + H5Sselect_adjust PURPOSE Adjust a selection by subtracting an offset USAGE @@ -990,25 +1040,35 @@ H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5Sselect_adjust_u(hid_t space_id, const hsize_t *offset) +H5Sselect_adjust(hid_t space_id, const hssize_t *offset) { H5S_t *space; + hsize_t low_bounds[H5S_MAX_RANK]; + hsize_t high_bounds[H5S_MAX_RANK]; + unsigned u; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE2("e", "i*h", space_id, offset); + H5TRACE2("e", "i*Hs", space_id, offset); if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "not a dataspace") if(NULL == offset) HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "NULL offset pointer") - if(H5S_select_adjust_u(space, offset) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't adjust selection"); + /* Check bounds */ + if(H5S_SELECT_BOUNDS(space, low_bounds, high_bounds) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get selection bounds") + for(u = 0; u < space->extent.rank; u++) + if(offset[u] > (hssize_t)low_bounds[u]) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "adjustment would move selection below zero offset") + + if(H5S_select_adjust_s(space, offset) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't adjust selection") done: FUNC_LEAVE_API(ret_value) -} /* end H5Sselect_adjust_u() */ +} /* end H5Sselect_adjust() */ /*-------------------------------------------------------------------------- |