summaryrefslogtreecommitdiffstats
path: root/src/H5Glink.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2019-06-18 18:42:53 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2019-06-18 18:42:53 (GMT)
commitd767e6a067aacee0d33a51d5c584d6676afc3df9 (patch)
tree55dbabe2ee20d5ad29c4317c21bae0ff7f838b6b /src/H5Glink.c
parent10535e0376d88e218cab782322bfc06f35835f31 (diff)
downloadhdf5-d767e6a067aacee0d33a51d5c584d6676afc3df9.zip
hdf5-d767e6a067aacee0d33a51d5c584d6676afc3df9.tar.gz
hdf5-d767e6a067aacee0d33a51d5c584d6676afc3df9.tar.bz2
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. Fixes HDFFV-10829
Diffstat (limited to 'src/H5Glink.c')
-rw-r--r--src/H5Glink.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/H5Glink.c b/src/H5Glink.c
index 82a2dcf..89f0266 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
*
*-------------------------------------------------------------------------
*/
@@ -423,6 +422,13 @@ H5G__link_sort_table(H5G_link_table_t *ltable, H5_index_t idx_type,
/* Sanity check */
HDassert(ltable);
+ /* Can't sort when empty since the links table will be NULL */
+ if(0 == ltable->nlinks)
+ return SUCCEED;
+
+ /* 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)