From: cantor Date: Thu, 22 Jul 2010 18:55:20 +0000 (+0000) Subject: Add null checks to helper methods. X-Git-Tag: 1.4.1~73 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fxmltooling.git;a=commitdiff_plain;h=3cf603b1397a3911eaf5bd2d804a5bd859888128 Add null checks to helper methods. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/branches/REL_1@765 de75baf8-a10c-0410-a50a-987c0e22f00f --- diff --git a/xmltooling/util/XMLHelper.cpp b/xmltooling/util/XMLHelper.cpp index 20d4058..34d82f6 100644 --- a/xmltooling/util/XMLHelper.cpp +++ b/xmltooling/util/XMLHelper.cpp @@ -209,18 +209,18 @@ bool XMLHelper::isNodeNamed(const xercesc::DOMNode* n, const XMLCh* ns, const XM const XMLCh* XMLHelper::getTextContent(const DOMElement* e) { - DOMNode* child=e->getFirstChild(); + DOMNode* child = e ? e->getFirstChild() : nullptr; while (child) { - if (child->getNodeType()==DOMNode::TEXT_NODE) + if (child->getNodeType() == DOMNode::TEXT_NODE) return child->getNodeValue(); - child=child->getNextSibling(); + child = child->getNextSibling(); } return nullptr; } DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n, const XMLCh* localName) { - DOMNode* child = n->getFirstChild(); + DOMNode* child = n ? n->getFirstChild() : nullptr; while (child && child->getNodeType() != DOMNode::ELEMENT_NODE) child = child->getNextSibling(); if (child && localName) { @@ -232,7 +232,7 @@ DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n, const XMLCh* local DOMElement* XMLHelper::getLastChildElement(const DOMNode* n, const XMLCh* localName) { - DOMNode* child = n->getLastChild(); + DOMNode* child = n ? n->getLastChild() : nullptr; while (child && child->getNodeType() != DOMNode::ELEMENT_NODE) child = child->getPreviousSibling(); if (child && localName) { @@ -260,7 +260,7 @@ DOMElement* XMLHelper::getLastChildElement(const DOMNode* n, const XMLCh* ns, co DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n, const XMLCh* localName) { - DOMNode* sib = n->getNextSibling(); + DOMNode* sib = n ? n->getNextSibling() : nullptr; while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE) sib = sib->getNextSibling(); if (sib && localName) { @@ -272,7 +272,7 @@ DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n, const XMLCh* loca DOMElement* XMLHelper::getPreviousSiblingElement(const DOMNode* n, const XMLCh* localName) { - DOMNode* sib = n->getPreviousSibling(); + DOMNode* sib = n ? n->getPreviousSibling() : nullptr; while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE) sib = sib->getPreviousSibling(); if (sib && localName) {