mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-24 06:50:08 +03:00
tree: Rework xmlTextMerge
Return NULL on error. Check for malloc failure. Check that nodes are distinct.
This commit is contained in:
parent
a3713f78e3
commit
4196454818
@ -234,9 +234,10 @@ extra_post_call = {
|
||||
xmlFreeNode(old) ; old = NULL ; }
|
||||
\t ret_val = NULL;""",
|
||||
"xmlTextMerge":
|
||||
"""if ((first != NULL) && (first->type != XML_TEXT_NODE)) {
|
||||
"""if (ret_val == NULL) {
|
||||
xmlUnlinkNode(second);
|
||||
xmlFreeNode(second) ; second = NULL ; }""",
|
||||
xmlFreeNode(second) ; second = NULL ;
|
||||
ret_val = first; }""",
|
||||
"xmlBuildQName":
|
||||
"""if ((ret_val != NULL) && (ret_val != ncname) &&
|
||||
(ret_val != prefix) && (ret_val != memory))
|
||||
|
@ -23412,9 +23412,10 @@ test_xmlTextMerge(void) {
|
||||
second = gen_xmlNodePtr_in(n_second, 1);
|
||||
|
||||
ret_val = xmlTextMerge(first, second);
|
||||
if ((first != NULL) && (first->type != XML_TEXT_NODE)) {
|
||||
if (ret_val == NULL) {
|
||||
xmlUnlinkNode(second);
|
||||
xmlFreeNode(second) ; second = NULL ; }
|
||||
xmlFreeNode(second) ; second = NULL ;
|
||||
ret_val = first; }
|
||||
desret_xmlNodePtr(ret_val);
|
||||
call_tests++;
|
||||
des_xmlNodePtr_in(n_first, first, 0);
|
||||
|
22
tree.c
22
tree.c
@ -6010,18 +6010,22 @@ xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) {
|
||||
* @first: the first text node
|
||||
* @second: the second text node being merged
|
||||
*
|
||||
* Merge two text nodes into one
|
||||
* Returns the first text node augmented
|
||||
* Merge the second text node into the first. The second node is
|
||||
* unlinked and freed.
|
||||
*
|
||||
* Returns the first text node augmented or NULL in case of error.
|
||||
*/
|
||||
xmlNodePtr
|
||||
xmlTextMerge(xmlNodePtr first, xmlNodePtr second) {
|
||||
if (first == NULL) return(second);
|
||||
if (second == NULL) return(first);
|
||||
if (first->type != XML_TEXT_NODE) return(first);
|
||||
if (second->type != XML_TEXT_NODE) return(first);
|
||||
if (second->name != first->name)
|
||||
return(first);
|
||||
xmlNodeAddContent(first, second->content);
|
||||
if ((first == NULL) || (first->type != XML_TEXT_NODE) ||
|
||||
(second == NULL) || (second->type != XML_TEXT_NODE) ||
|
||||
(first == second) ||
|
||||
(first->name != second->name))
|
||||
return(NULL);
|
||||
|
||||
if (xmlNodeAddContent(first, second->content) != 0)
|
||||
return(NULL);
|
||||
|
||||
xmlUnlinkNode(second);
|
||||
xmlFreeNode(second);
|
||||
return(first);
|
||||
|
Loading…
x
Reference in New Issue
Block a user