[libxml++] Node: Improve some null-pointer checks
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Node: Improve some null-pointer checks
- Date: Wed, 31 Jul 2013 07:27:13 +0000 (UTC)
commit 798ac733cd74ae0137be0631e6380db7b6932a9f
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Jul 31 09:25:20 2013 +0200
Node: Improve some null-pointer checks
* libxml++/nodes/node.cc:
If we are going to check impl_ for null, we may as well do it
where it makes most sense. Note that we do not bother yet to check
for this in other functions. If we did this consistently we would
want a sensible way to respond to it, such as an exception.
Bug #705187 (Gaurav)
libxml++/nodes/node.cc | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/libxml++/nodes/node.cc b/libxml++/nodes/node.cc
index 44bcf91..ade377e 100644
--- a/libxml++/nodes/node.cc
+++ b/libxml++/nodes/node.cc
@@ -510,6 +510,9 @@ Glib::ustring Node::eval_to_string(const Glib::ustring& xpath, const PrefixNsMap
Glib::ustring Node::get_namespace_prefix() const
{
+ if(!impl_)
+ return Glib::ustring();
+
if(impl_->type == XML_DOCUMENT_NODE || impl_->type == XML_ENTITY_DECL)
{
//impl_ is actually of type xmlDoc or xmlEntity, instead of just xmlNode.
@@ -527,8 +530,7 @@ Glib::ustring Node::get_namespace_prefix() const
const xmlAttribute* const attr = reinterpret_cast<const xmlAttribute*>(impl_);
return attr->prefix ? (const char*)attr->prefix : "";
}
-
- if(impl_ && impl_->ns && impl_->ns->prefix)
+ else if(impl_->ns && impl_->ns->prefix)
return (char*)impl_->ns->prefix;
else
return Glib::ustring();
@@ -536,6 +538,9 @@ Glib::ustring Node::get_namespace_prefix() const
Glib::ustring Node::get_namespace_uri() const
{
+ if(!impl_)
+ return Glib::ustring();
+
if(impl_->type == XML_DOCUMENT_NODE ||
impl_->type == XML_ENTITY_DECL ||
impl_->type == XML_ATTRIBUTE_DECL)
@@ -550,7 +555,7 @@ Glib::ustring Node::get_namespace_uri() const
return Glib::ustring();
}
- if(impl_ && impl_->ns && impl_->ns->href)
+ if(impl_->ns && impl_->ns->href)
return (char*)impl_->ns->href;
else
return Glib::ustring();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]