From b4567b402bb40890b4ff3fcf5a8f433921c321ec Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 5 Apr 2009 20:59:41 +0300 Subject: [PATCH] Bug 1071: Add precautionary assertions and recovery --- src/dom/node.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/dom/node.c b/src/dom/node.c index 4e4d929f2..fbf2d5c05 100644 --- a/src/dom/node.c +++ b/src/dom/node.c @@ -233,6 +233,7 @@ get_dom_node_list_pos(struct dom_node_list *list, struct dom_node *node) int i; assert(list); + if_assert_failed return -1; foreach_dom_node (list, entry, i) { if (entry == node) @@ -257,11 +258,20 @@ get_dom_node_prev(struct dom_node *node) int index; assert(node->parent); + if_assert_failed return NULL; list = get_dom_node_list(node->parent, node); + /* node->parent != NULL, so the node must be in the + * appropriate list of the parent; the list thus cannot be + * empty. */ if (!list) return NULL; + assert(*list); + if_assert_failed return NULL; index = get_dom_node_list_pos(*list, node); + assert(index >= 0); /* in particular, not -1 */ + if_assert_failed return NULL; + if (index > 0) return (*list)->entries[index - 1]; @@ -275,11 +285,20 @@ get_dom_node_next(struct dom_node *node) int index; assert(node->parent); + if_assert_failed return NULL; list = get_dom_node_list(node->parent, node); + /* node->parent != NULL, so the node must be in the + * appropriate list of the parent; the list thus cannot be + * empty. */ if (!list) return NULL; + assert(*list); + if_assert_failed return NULL; index = get_dom_node_list_pos(*list, node); + assert(index >= 0); /* in particular, not -1 */ + if_assert_failed return NULL; + if (index + 1 < (*list)->size) return (*list)->entries[index + 1];