mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-04-12 17:31:09 +08:00
Align behavior of H5Aget_name_by_idx with H5Aget_name when a NULL buffer is supplied
This commit is contained in:
parent
3f727a272c
commit
2d7eb9a4c3
@ -951,6 +951,8 @@ H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
|
||||
if(!obj_name || !*obj_name)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
|
||||
if(!name && size)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name cannot be NULL if size is non-zero")
|
||||
if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
|
||||
if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
|
||||
|
57
test/tattr.c
57
test/tattr.c
@ -150,6 +150,8 @@ float attr_data5=-5.123F; /* Test data for 5th attribute */
|
||||
#define INVALID_RENAME_TEST_ATTR_NAME "InvalidRenameTestAttr"
|
||||
#define INVALID_RENAME_TEST_NEW_ATTR_NAME "InvalidRenameTestNewAttr"
|
||||
|
||||
/* Used by test_attr_get_name_invalid_buf() */
|
||||
#define GET_NAME_INVALID_BUF_TEST_ATTR_NAME "InvalidNameBufferTestAttr"
|
||||
|
||||
/* Attribute iteration struct */
|
||||
typedef struct {
|
||||
@ -6137,6 +6139,60 @@ test_attr_rename_invalid_name(hid_t fcpl, hid_t fapl)
|
||||
CHECK(err_ret, FAIL, "H5Fclose");
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************
|
||||
**
|
||||
** test_attr_get_name_invalid_buf(): A test to ensure that
|
||||
** passing a NULL buffer to H5Aget_name(_by_idx) when
|
||||
** the 'size' parameter is non-zero doesn't cause bad
|
||||
** behavior.
|
||||
**
|
||||
****************************************************************/
|
||||
static void
|
||||
test_attr_get_name_invalid_buf(hid_t fcpl, hid_t fapl)
|
||||
{
|
||||
ssize_t err_ret = -1;
|
||||
hid_t fid;
|
||||
hid_t attr;
|
||||
hid_t sid;
|
||||
|
||||
/* Create dataspace for attribute */
|
||||
sid = H5Screate(H5S_SCALAR);
|
||||
CHECK(sid, FAIL, "H5Screate");
|
||||
|
||||
/* Create file */
|
||||
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
|
||||
CHECK(fid, FAIL, "H5Fcreate");
|
||||
|
||||
/* Create attribute */
|
||||
attr = H5Acreate2(fid, GET_NAME_INVALID_BUF_TEST_ATTR_NAME, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
|
||||
CHECK(attr, FAIL, "H5Acreate2");
|
||||
|
||||
H5E_BEGIN_TRY {
|
||||
err_ret = H5Aget_name(attr, 1, NULL);
|
||||
} H5E_END_TRY;
|
||||
|
||||
VERIFY(err_ret, FAIL, "H5Aget_name");
|
||||
|
||||
H5E_BEGIN_TRY {
|
||||
err_ret = H5Aget_name_by_idx(fid, ".", H5_INDEX_NAME, H5_ITER_INC, 0, NULL, 1, H5P_DEFAULT);
|
||||
} H5E_END_TRY;
|
||||
|
||||
VERIFY(err_ret, FAIL, "H5Aget_name_by_idx");
|
||||
|
||||
/* Close dataspace */
|
||||
err_ret = H5Sclose(sid);
|
||||
CHECK(err_ret, FAIL, "H5Sclose");
|
||||
|
||||
/* Close attribute */
|
||||
err_ret = H5Aclose(attr);
|
||||
CHECK(err_ret, FAIL, "H5Aclose");
|
||||
|
||||
/* Close file */
|
||||
err_ret = H5Fclose(fid);
|
||||
CHECK(err_ret, FAIL, "H5Fclose");
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************
|
||||
**
|
||||
@ -11176,6 +11232,7 @@ test_attr(void)
|
||||
test_attr_many(new_format, my_fcpl, my_fapl); /* Test storing lots of attributes */
|
||||
test_attr_info_null_info_pointer(my_fcpl, my_fapl); /* Test passing a NULL attribute info pointer to H5Aget_info(_by_name/_by_idx) */
|
||||
test_attr_rename_invalid_name(my_fcpl, my_fapl); /* Test passing a NULL or empty attribute name to H5Arename(_by_name) */
|
||||
test_attr_get_name_invalid_buf(my_fcpl, my_fapl); /* Test passing NULL buffer to H5Aget_name(_by_idx) */
|
||||
|
||||
/* New attribute API routine tests
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user