isl_schedule_tree_n_children: explicitly handle missing children
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Tue, 7 Aug 2018 13:16:41 +0000 (7 15:16 +0200)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Sat, 25 Aug 2018 08:16:06 +0000 (25 10:16 +0200)
The functions isl_*_list_n_* return 0 on invalid (NULL) input,
but isl_schedule_tree_n_children should not rely on this behavior.
Instead, it should handle the absence of children
(in which case the "children" has a valid NULL value) explicitly.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
isl_schedule_tree.c

index c6e55d5..4d0e573 100644 (file)
@@ -714,12 +714,16 @@ int isl_schedule_tree_has_children(__isl_keep isl_schedule_tree *tree)
 }
 
 /* Return the number of children of "tree", excluding implicit leaves.
+ * The "children" field is NULL if there are
+ * no children (except for the implicit leaves).
  */
 int isl_schedule_tree_n_children(__isl_keep isl_schedule_tree *tree)
 {
        if (!tree)
                return -1;
 
+       if (!tree->children)
+               return 0;
        return isl_schedule_tree_list_n_schedule_tree(tree->children);
 }