diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-02-21 20:21:33 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-02-21 20:22:23 +0000 |
commit | 38c82c0d1e4474aff9b601fcf6ba9578396346b9 (patch) | |
tree | 4870dfae05844331b4a6914ac8290f0f4fdcdbfa | |
parent | 010d1d5212cc906214feec4cfd25daca2dd2033e (diff) | |
download | libdom-38c82c0d1e4474aff9b601fcf6ba9578396346b9.tar.gz libdom-38c82c0d1e4474aff9b601fcf6ba9578396346b9.tar.bz2 |
Deal with some scan-build-identified potential problems
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/core/node.c | 17 | ||||
-rw-r--r-- | src/html/html_select_element.c | 6 |
2 files changed, 22 insertions, 1 deletions
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); |