From 38c82c0d1e4474aff9b601fcf6ba9578396346b9 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 21 Feb 2020 20:21:33 +0000 Subject: Deal with some scan-build-identified potential problems Signed-off-by: Daniel Silverstone --- src/core/node.c | 17 ++++++++++++++++- src/html/html_select_element.c | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/node.c b/src/core/node.c index 87ad837..9ba277e 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -2172,7 +2172,9 @@ dom_exception _dom_node_detach_range(dom_node_internal *first, * * This is not implemented in terms of attach/detach in case * we want to perform any special replacement-related behaviour - * at a later date. + * at a later date. If the replacement is essentially empty (either NULL + * or an empty document fragment node) then this essentially just removes + * the old node from its parent. It is up to the caller to deal with that. */ void _dom_node_replace(dom_node_internal *old, dom_node_internal *replacement) @@ -2190,6 +2192,19 @@ void _dom_node_replace(dom_node_internal *old, last = replacement; } + if (first == NULL) { + /* All we're doing is removing old */ + if (old->previous == NULL) { + old->parent->first_child = old->next; + } + if (old->next == NULL) { + old->parent->last_child = old->previous; + } + old->previous = old->next = old->parent = NULL; + return; + } + + /* We're replacing old with first-to-last */ first->previous = old->previous; last->next = old->next; diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c index ff549b2..0801d0a 100644 --- a/src/html/html_select_element.c +++ b/src/html/html_select_element.c @@ -213,6 +213,9 @@ dom_exception dom_html_select_element_get_selected_index( dom_html_options_collection *col; err = _dom_html_select_element_make_collection(ele, &col); + if (err != DOM_NO_ERR) { + return err; + } err = dom_html_options_collection_get_length(col, &len); if (err != DOM_NO_ERR) { @@ -266,6 +269,9 @@ dom_exception dom_html_select_element_set_selected_index( dom_html_options_collection *col; err = _dom_html_select_element_make_collection(ele, &col); + if (err != DOM_NO_ERR) { + return err; + } err = dom_html_options_collection_item(col, index, &option); -- cgit v1.2.3