- a little bit of code hardening (looking for invalid data conditions and NULL's)

This commit is contained in:
Mark Vejvoda 2011-01-10 21:23:52 +00:00
parent a9534e727e
commit 8bf83c03a8

View File

@ -187,28 +187,30 @@ XmlNode::XmlNode(DOMNode *node){
} }
//get name //get name
char str[strSize]; char str[strSize]="";
XMLString::transcode(node->getNodeName(), str, strSize-1); XMLString::transcode(node->getNodeName(), str, strSize-1);
name= str; name= str;
//check document //check document
if(node->getNodeType()==DOMNode::DOCUMENT_NODE){ if(node->getNodeType() == DOMNode::DOCUMENT_NODE) {
name="document"; name="document";
} }
//check children //check children
for(unsigned int i=0; i<node->getChildNodes()->getLength(); ++i){ if(node->getChildNodes() != NULL) {
DOMNode *currentNode= node->getChildNodes()->item(i); for(unsigned int i = 0; i < node->getChildNodes()->getLength(); ++i) {
if(currentNode->getNodeType()==DOMNode::ELEMENT_NODE){ DOMNode *currentNode= node->getChildNodes()->item(i);
XmlNode *xmlNode= new XmlNode(currentNode); if(currentNode != NULL && currentNode->getNodeType()==DOMNode::ELEMENT_NODE){
children.push_back(xmlNode); XmlNode *xmlNode= new XmlNode(currentNode);
} children.push_back(xmlNode);
}
}
} }
//check attributes //check attributes
DOMNamedNodeMap *domAttributes= node->getAttributes(); DOMNamedNodeMap *domAttributes= node->getAttributes();
if(domAttributes!=NULL){ if(domAttributes != NULL) {
for(unsigned int i=0; i<domAttributes->getLength(); ++i){ for(unsigned int i = 0; i < domAttributes->getLength(); ++i) {
DOMNode *currentNode= domAttributes->item(i); DOMNode *currentNode= domAttributes->item(i);
if(currentNode->getNodeType()==DOMNode::ATTRIBUTE_NODE){ if(currentNode->getNodeType()==DOMNode::ATTRIBUTE_NODE){
XmlAttribute *xmlAttribute= new XmlAttribute(domAttributes->item(i)); XmlAttribute *xmlAttribute= new XmlAttribute(domAttributes->item(i));
@ -218,7 +220,7 @@ XmlNode::XmlNode(DOMNode *node){
} }
//get value //get value
if(node->getNodeType()==DOMNode::ELEMENT_NODE && children.size()==0){ if(node->getNodeType() == DOMNode::ELEMENT_NODE && children.size() == 0) {
char *textStr= XMLString::transcode(node->getTextContent()); char *textStr= XMLString::transcode(node->getTextContent());
text= textStr; text= textStr;
XMLString::release(&textStr); XMLString::release(&textStr);