[svn-r24681] Description:

Fix for HDF5/HDFFV-8620 H5Rget_name with NULL name parameter fails.
The name parameter now excepts NULL, in which case the length of then
name is returned.


Tested: jam (intel and gnu)
This commit is contained in:
Scot Breitenfeld 2014-02-04 10:11:20 -05:00
parent ddf75b10f6
commit ee10548723
3 changed files with 26 additions and 6 deletions

View File

@ -894,7 +894,6 @@ H5R_get_name(H5F_t *f, hid_t lapl_id, hid_t dxpl_id, hid_t id, H5R_type_t ref_ty
/* Check args */
HDassert(f);
HDassert(_ref);
HDassert(name);
/* Initialize the object location */
H5O_loc_reset(&oloc);
@ -965,8 +964,10 @@ done:
object that the dataset is located within.
H5R_type_t ref_type; IN: Type of reference
void *ref; IN: Reference to query.
char *name; OUT: Buffer to place name of object referenced
size_t size; IN: Size of name buffer
char *name; OUT: Buffer to place name of object referenced. If NULL
then this call will return the size in bytes of name.
size_t size; IN: Size of name buffer (user needs to include NULL terminator
when passing in the size)
RETURNS
Non-negative length of the path on success, Negative on failure
@ -978,6 +979,12 @@ done:
This may not be the only path to that object.
EXAMPLES
REVISION LOG
M. Scot Breitenfeld
22 January 2014
Changed the behavior for the returned value of the function when name is NULL.
If name is NULL then size is ignored and the function returns the size
of the name buffer (not including the NULL terminator), it still returns
negative on failure.
--------------------------------------------------------------------------*/
ssize_t
H5Rget_name(hid_t id, H5R_type_t ref_type, const void *_ref, char *name,

View File

@ -2524,6 +2524,14 @@ test_obj_ref(hid_t fapl)
if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR
if(!((HDstrcmp(buf, "/Dataset3") == 0) &&(i == 9))) TEST_ERROR
*buf = '\0';
/* Check H5Rget_name returns the correct length of the name when name is NULL */
i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], NULL, 0);
if(i != 9) TEST_ERROR
/* Make sure size parameter is ignored */
i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], NULL, 200);
if(i != 9) TEST_ERROR
i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], (char*)buf, sizeof(buf));
if(!((HDstrcmp(buf, "/Dataset3") == 0) &&(i == 9))) TEST_ERROR
PASSED()
@ -2761,7 +2769,12 @@ test_reg_ref(hid_t fapl)
/* Get name of the dataset the first region reference points to using H5Rget_name */
TESTING("H5Rget_name to get name from region reference(hyperslab)");
*buf1 = '\0';
name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, NAME_BUF_SIZE);
/* Check H5Rget_name returns the correct length of the name when name is NULL */
name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], NULL, 0);
if(name_size1 != 7) TEST_ERROR
name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, NAME_BUF_SIZE );
if(!((HDstrcmp(buf1, "/MATRIX") == 0) &&(name_size1 == 7))) TEST_ERROR
PASSED()

View File

@ -205,9 +205,9 @@ test_reference_params(void)
name_size = H5Rget_name(-1, H5R_DATASET_REGION, &rbuf[0], NULL, 0);
VERIFY(name_size, FAIL, "H5Rget_name loc_id");
name_size = H5Rget_name(fid1, H5R_DATASET_REGION, NULL, NULL, 0);
VERIFY(ret, FAIL, "H5Rget_name ref");
VERIFY(name_size, FAIL, "H5Rget_name ref");
name_size = H5Rget_name(fid1, H5R_MAXTYPE, &rbuf[0], NULL, 0);
VERIFY(ret, FAIL, "H5Rget_name type");
VERIFY(name_size, FAIL, "H5Rget_name type");
/* Test parameters to H5Rget_region */
ret = H5Rget_region(-1, H5R_OBJECT, &rbuf[0]);