]> granicus.if.org Git - php/commitdiff
MFH: fix bug #41833 (addChild() on a non-existent node, no node created, getName...
authorRob Richards <rrichards@php.net>
Tue, 31 Jul 2007 15:40:49 +0000 (15:40 +0000)
committerRob Richards <rrichards@php.net>
Tue, 31 Jul 2007 15:40:49 +0000 (15:40 +0000)
ext/simplexml/simplexml.c

index 47260f965f6517ab083914a71898a397047a837b..c97bfafc7213e6a8a3fdd449220b678959ca9fe2 100644 (file)
@@ -1563,6 +1563,11 @@ SXE_METHOD(addChild)
 
        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
 
+       if (node == NULL) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add child. Parent is not a permanent member of the XML tree");
+               return; 
+       }
+
        localname = xmlSplitQName2((xmlChar *)qname, &prefix);
        if (localname == NULL) {
                localname = xmlStrdup((xmlChar *)qname);
@@ -1575,9 +1580,7 @@ SXE_METHOD(addChild)
                        newnode->ns = NULL;
                        nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix);
                } else {
-                       if (node) {
-                               nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri);
-                       }
+                       nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri);
                        if (nsptr == NULL) {
                                nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix);
                        }