From d3d17da6e5ddb8be5e1085ac653d79e46708169a Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Fri, 16 Mar 2012 16:21:32 +0100 Subject: [PATCH] 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. --- ChangeLog | 9 +++++++++ ixml/src/document.c | 8 +++++++- ixml/src/node.c | 28 +++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 739ed83..c2619d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,15 @@ Version 1.6.16 ******************************************************************************* +2012-03-16 Fabrice Fontaine + + 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 Add more explicit casts and remove dead code diff --git a/ixml/src/document.c b/ixml/src/document.c index 9aad2ef..9a72b0e 100644 --- a/ixml/src/document.c +++ b/ixml/src/document.c @@ -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; } diff --git a/ixml/src/node.c b/ixml/src/node.c index 1b79cb1..c20b841 100644 --- a/ixml/src/node.c +++ b/ixml/src/node.c @@ -655,6 +655,7 @@ static IXML_Node *ixmlNode_cloneTextNode( IXML_Node *nodeptr) { IXML_Node *newNode = NULL; + int rc; assert(nodeptr != NULL); @@ -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; } @@ -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; }