[libxml++] Document, Element, Node: Remove unnecessary tests for null pointers.



commit 37d0e5ebf44ac585fe11cf5993f2b07304dcaeb3
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Aug 7 19:31:05 2012 +0200

    Document, Element, Node: Remove unnecessary tests for null pointers.
    
    * libxml++/document.cc:
    * libxml++/nodes/element.cc:
    * libxml++/nodes/node.cc: Remove tests for null pointer before calling
    xmlFreeNode(), which does nothing if given a null pointer. These unnecessary
    tests were newly added when error handling was improved. Bug #635846.

 ChangeLog                 |   10 ++++++++++
 libxml++/document.cc      |    6 ++----
 libxml++/nodes/element.cc |   21 +++++++--------------
 libxml++/nodes/node.cc    |    9 +++------
 4 files changed, 22 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1dfb300..4f71d8a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-08-07  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+ 
+	Document, Element, Node: Remove unnecessary tests for null pointers.
+
+	* libxml++/document.cc:
+	* libxml++/nodes/element.cc:
+	* libxml++/nodes/node.cc: Remove tests for null pointer before calling
+	xmlFreeNode(), which does nothing if given a null pointer. These unnecessary
+	tests were newly added when error handling was improved. Bug #635846.
+
 2012-08-05  Kjell Ahlstedt  <kjell ahlstedt bredband net>
  
 	Schema::set_document(): Create empty document.
diff --git a/libxml++/document.cc b/libxml++/document.cc
index d07f07d..99854e7 100644
--- a/libxml++/document.cc
+++ b/libxml++/document.cc
@@ -181,8 +181,7 @@ CommentNode* Document::add_comment(const Glib::ustring& content)
   xmlNode* node = xmlAddChild((xmlNode*)impl_, child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add comment node \"" + content + "\"");
   }
   Node::create_wrapper(node);
@@ -196,8 +195,7 @@ ProcessingInstructionNode* Document::add_processing_instruction(
   xmlNode* node = xmlAddChild((xmlNode*)impl_, child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add processing instruction node " + name);
   }
   Node::create_wrapper(node);
diff --git a/libxml++/nodes/element.cc b/libxml++/nodes/element.cc
index 0fac9fb..73a128a 100644
--- a/libxml++/nodes/element.cc
+++ b/libxml++/nodes/element.cc
@@ -163,8 +163,7 @@ TextNode* Element::add_child_text(const Glib::ustring& content)
     xmlNode* node = xmlAddChild(cobj(), child);
     if (!node)
     {
-      if (child)
-        xmlFreeNode(child);
+      xmlFreeNode(child);
       throw internal_error("Could not add text node \"" + content + "\"");
     }
     Node::create_wrapper(node);
@@ -186,8 +185,7 @@ TextNode* Element::add_child_text(xmlpp::Node* previous_sibling, const Glib::ust
     xmlNode* node = xmlAddNextSibling(previous_sibling->cobj(), child);
     if (!node)
     {
-      if (child)
-        xmlFreeNode(child);
+      xmlFreeNode(child);
       throw internal_error("Could not add text node \"" + content + "\"");
     }
     Node::create_wrapper(node);
@@ -209,8 +207,7 @@ TextNode* Element::add_child_text_before(xmlpp::Node* next_sibling, const Glib::
     xmlNode* node = xmlAddPrevSibling(next_sibling->cobj(), child);
     if (!node)
     {
-      if (child)
-        xmlFreeNode(child);
+      xmlFreeNode(child);
       throw internal_error("Could not add text node \"" + content + "\"");
     }
     Node::create_wrapper(node);
@@ -260,8 +257,7 @@ CommentNode* Element::add_child_comment(const Glib::ustring& content)
   xmlNode* node = xmlAddChild(cobj(), child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add comment node \"" + content + "\"");
   }
   Node::create_wrapper(node);
@@ -275,8 +271,7 @@ CdataNode* Element::add_child_cdata(const Glib::ustring& content)
   xmlNode* node = xmlAddChild(cobj(), child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add CDATA node \"" + content + "\"");
   }
   Node::create_wrapper(node);
@@ -300,8 +295,7 @@ EntityReference* Element::add_child_entity_reference(const Glib::ustring& name)
   xmlNode* node = xmlAddChild(cobj(), child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add entity reference node " + name);
   }
   Node::create_wrapper(node);
@@ -315,8 +309,7 @@ ProcessingInstructionNode* Element::add_child_processing_instruction(
   xmlNode* node = xmlAddChild(cobj(), child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add processing instruction node " + name);
   }
   Node::create_wrapper(node);
diff --git a/libxml++/nodes/node.cc b/libxml++/nodes/node.cc
index 0ba6822..d9af71c 100644
--- a/libxml++/nodes/node.cc
+++ b/libxml++/nodes/node.cc
@@ -226,8 +226,7 @@ Element* Node::add_child(const Glib::ustring& name,
   _xmlNode* node = xmlAddChild(impl_, child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add child element node " + name);
   }
   Node::create_wrapper(node);
@@ -245,8 +244,7 @@ Element* Node::add_child(xmlpp::Node* previous_sibling,
   _xmlNode* node = xmlAddNextSibling(previous_sibling->cobj(), child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add child element node " + name);
   }
   Node::create_wrapper(node);
@@ -264,8 +262,7 @@ Element* Node::add_child_before(xmlpp::Node* next_sibling,
   _xmlNode* node = xmlAddPrevSibling(next_sibling->cobj(), child);
   if (!node)
   {
-    if (child)
-      xmlFreeNode(child);
+    xmlFreeNode(child);
     throw internal_error("Could not add child element node " + name);
   }
   Node::create_wrapper(node);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]