[gnote] Fix errors in new xml functions



commit 3ee63404615ca2355bef44affa5dec49ad45fb38
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Fri Feb 3 23:28:01 2012 +0200

    Fix errors in new xml functions
    
    Make xml_node_xpath_find NULL safe.
    Fix exception in xml_node_get_attribute.

 src/sharp/xml.cpp |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/src/sharp/xml.cpp b/src/sharp/xml.cpp
index eac6d85..531f6d9 100644
--- a/src/sharp/xml.cpp
+++ b/src/sharp/xml.cpp
@@ -36,13 +36,16 @@ namespace sharp {
   XmlNodeSet xml_node_xpath_find(const xmlNodePtr node, 
                                  const char * xpath)
   {
+    XmlNodeSet nodes;
+
+    if(!node) {
+      return nodes;
+    }
     xmlXPathContext* ctxt = xmlXPathNewContext(node->doc);
     ctxt->node = node;
 
     xmlXPathObject* result = xmlXPathEval((const xmlChar*)xpath, ctxt);
 
-    XmlNodeSet nodes;
-
     if(result && (result->type == XPATH_NODESET)) {
       xmlNodeSetPtr nodeset = result->nodesetval;
 
@@ -109,7 +112,8 @@ namespace sharp {
   std::string xml_node_get_attribute(const xmlNodePtr node,
                                      const char * attr_name)
   {
-    return reinterpret_cast<char*>(xmlGetProp(node, reinterpret_cast<const xmlChar*>(attr_name)));
+    char *res = reinterpret_cast<char*>(xmlGetProp(node, reinterpret_cast<const xmlChar*>(attr_name)));
+    return res ? res : "";
   }
 
 }



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