Navigation Menu

Skip to content

Commit

Permalink
Check return code in ixml
Browse files Browse the repository at this point in the history
Check return code of ixmlDocument_CreateElementEx in
ixmlDocument_CreateElement.
Check return code of ixmlNode_setNodeName and ixmlNode_setNodeValue in
ixmlNode_cloneCDATASect and ixmlNode_cloneTextNode.
  • Loading branch information
ffontaine committed Mar 16, 2012
1 parent e0444b2 commit d3d17da
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Expand Up @@ -2,6 +2,15 @@
Version 1.6.16
*******************************************************************************

2012-03-16 Fabrice Fontaine <fabrice.fontaine(at)orange.com>

Check return code in ixml

Check return code of ixmlDocument_CreateElementEx in
ixmlDocument_CreateElement.
Check return code of ixmlNode_setNodeName and ixmlNode_setNodeValue in
ixmlNode_cloneCDATASect and ixmlNode_cloneTextNode.

2012-03-16 Fabrice Fontaine <fabrice.fontaine(at)orange.com>

Add more explicit casts and remove dead code
Expand Down
8 changes: 7 additions & 1 deletion ixml/src/document.c
Expand Up @@ -165,8 +165,14 @@ IXML_Element *ixmlDocument_createElement(
const DOMString tagName)
{
IXML_Element *newElement = NULL;
int ret = IXML_SUCCESS;

ixmlDocument_createElementEx(doc, tagName, &newElement);
ret = ixmlDocument_createElementEx(doc, tagName, &newElement);
if (ret != IXML_SUCCESS) {
IxmlPrintf(__FILE__, __LINE__, "ixmlDocument_createElement",
"Error %d\n", ret);
return NULL;
}
return newElement;
}

Expand Down
28 changes: 23 additions & 5 deletions ixml/src/node.c
Expand Up @@ -655,6 +655,7 @@ static IXML_Node *ixmlNode_cloneTextNode(
IXML_Node *nodeptr)
{
IXML_Node *newNode = NULL;
int rc;

assert(nodeptr != NULL);

Expand All @@ -663,8 +664,16 @@ static IXML_Node *ixmlNode_cloneTextNode(
return NULL;
} else {
ixmlNode_init(newNode);
ixmlNode_setNodeName(newNode, nodeptr->nodeName);
ixmlNode_setNodeValue(newNode, nodeptr->nodeValue);
rc = ixmlNode_setNodeName(newNode, nodeptr->nodeName);
if (rc != IXML_SUCCESS) {
ixmlNode_free(newNode);
return NULL;
}
rc = ixmlNode_setNodeValue(newNode, nodeptr->nodeValue);
if (rc != IXML_SUCCESS) {
ixmlNode_free(newNode);
return NULL;
}
newNode->nodeType = eTEXT_NODE;
}

Expand All @@ -683,15 +692,24 @@ static IXML_CDATASection *ixmlNode_cloneCDATASect(
IXML_CDATASection *newCDATA = NULL;
IXML_Node *newNode;
IXML_Node *srcNode;
int rc;

assert(nodeptr != NULL);
newCDATA = (IXML_CDATASection *)malloc(sizeof (IXML_CDATASection));
if (newCDATA != NULL) {
newNode = (IXML_Node *)newCDATA;
ixmlNode_init(newNode);
ixmlCDATASection_init(newCDATA);
srcNode = (IXML_Node *)nodeptr;
ixmlNode_setNodeName(newNode, srcNode->nodeName);
ixmlNode_setNodeValue(newNode, srcNode->nodeValue);
rc = ixmlNode_setNodeName(newNode, srcNode->nodeName);
if (rc != IXML_SUCCESS) {
ixmlCDATASection_free(newCDATA);
return NULL;
}
rc = ixmlNode_setNodeValue(newNode, srcNode->nodeValue);
if (rc != IXML_SUCCESS) {
ixmlCDATASection_free(newCDATA);
return NULL;
}
newNode->nodeType = eCDATA_SECTION_NODE;
}

Expand Down

0 comments on commit d3d17da

Please sign in to comment.