summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2019-06-18 22:36:42 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2019-06-18 22:36:42 (GMT)
commitc6e21cede788790b39af4a46a8bc15e49e382346 (patch)
treef2a5559c4ec1a95e43dad4b0d3f8d5fdbb904100 /src
parent8973ba46c6fd72caac146c254349df46bb57717d (diff)
parent0a75da70a61d41a0bf20a5c617f3eb678ed0b103 (diff)
downloadhdf5-c6e21cede788790b39af4a46a8bc15e49e382346.zip
hdf5-c6e21cede788790b39af4a46a8bc15e49e382346.tar.gz
hdf5-c6e21cede788790b39af4a46a8bc15e49e382346.tar.bz2
Merge pull request #1748 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:links_iterate_zero_bug to develop
* commit '0a75da70a61d41a0bf20a5c617f3eb678ed0b103': Yanked qsort assert Switched to HGOTO_DONE() in the links code. Updated the HDqsort() macro to ensure we don't pass NULL buffers to qsort(3) in the future. Fixed a bug in the links code where iterating over an empty group would pass a NULL pointer to qsort(3), which is undefined behavior.
Diffstat (limited to 'src')
-rw-r--r--src/H5Glink.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/H5Glink.c b/src/H5Glink.c
index 82a2dcf..04ccbc5 100644
--- a/src/H5Glink.c
+++ b/src/H5Glink.c
@@ -402,15 +402,14 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5G__link_sort_table
+ * Function: H5G__link_sort_table
*
* Purpose: Sort table containing a list of links for a group
*
- * Return: Success: Non-negative
- * Failure: Negative
+ * Return: SUCCEED/FAIL
*
- * Programmer: Quincey Koziol
- * Nov 20, 2006
+ * Programmer: Quincey Koziol
+ * Nov 20, 2006
*
*-------------------------------------------------------------------------
*/
@@ -418,11 +417,20 @@ herr_t
H5G__link_sort_table(H5G_link_table_t *ltable, H5_index_t idx_type,
H5_iter_order_t order)
{
+ herr_t ret_value = SUCCEED;
+
FUNC_ENTER_PACKAGE_NOERR
/* Sanity check */
HDassert(ltable);
+ /* Can't sort when empty since the links table will be NULL */
+ if(0 == ltable->nlinks)
+ HGOTO_DONE(ret_value);
+
+ /* This should never be NULL if the number of links is non-zero */
+ HDassert(ltable->lnks);
+
/* Pick appropriate sorting routine */
if(idx_type == H5_INDEX_NAME) {
if(order == H5_ITER_INC)
@@ -442,6 +450,7 @@ H5G__link_sort_table(H5G_link_table_t *ltable, H5_index_t idx_type,
HDassert(order == H5_ITER_NATIVE);
} /* end else */
+done:
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5G__link_sort_table() */