Improve ixml

Remove "implicit integer conversions" and
"dereference NULL return value" errors in ixml part.
This commit is contained in:
Fabrice Fontaine 2012-03-10 17:58:12 +01:00
parent 41412c16ef
commit 06660b6383
11 changed files with 97 additions and 65 deletions

View File

@ -2,6 +2,13 @@
Version 1.6.16 Version 1.6.16
******************************************************************************* *******************************************************************************
2012-03-10 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Improve ixml
Remove "implicit integer conversions" and
"dereference NULL return value" errors in ixml part.
2012-03-10 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com> 2012-03-10 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
Exclude IPv6 stuff in SearchByTarget when UPNP_ENABLE_IPV6 is not defined. Exclude IPv6 stuff in SearchByTarget when UPNP_ENABLE_IPV6 is not defined.

View File

@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -40,6 +41,7 @@ void ixmlAttr_init(IN IXML_Attr *attr)
{ {
if (attr != NULL) { if (attr != NULL) {
memset(attr, 0, sizeof (IXML_Attr)); memset(attr, 0, sizeof (IXML_Attr));
attr->ownerElement = NULL;
} }
} }

View File

@ -185,7 +185,7 @@ int ixmlDocument_createDocumentEx(IXML_Document **rtDoc)
ixmlDocument_init(doc); ixmlDocument_init(doc);
doc->n.nodeName = strdup(DOCUMENTNODENAME); doc->n.nodeName = strdup((const char*)DOCUMENTNODENAME);
if (doc->n.nodeName == NULL) { if (doc->n.nodeName == NULL) {
ixmlDocument_free(doc); ixmlDocument_free(doc);
doc = NULL; doc = NULL;
@ -234,7 +234,7 @@ int ixmlDocument_createTextNodeEx(
/* initialize the node */ /* initialize the node */
ixmlNode_init(returnNode); ixmlNode_init(returnNode);
returnNode->nodeName = strdup(TEXTNODENAME); returnNode->nodeName = strdup((const char*)TEXTNODENAME);
if (returnNode->nodeName == NULL) { if (returnNode->nodeName == NULL) {
ixmlNode_free(returnNode); ixmlNode_free(returnNode);
returnNode = NULL; returnNode = NULL;
@ -320,7 +320,8 @@ IXML_Attr *ixmlDocument_createAttribute(
{ {
IXML_Attr *attrNode = NULL; IXML_Attr *attrNode = NULL;
ixmlDocument_createAttributeEx(doc, name, &attrNode); if(ixmlDocument_createAttributeEx(doc, name, &attrNode) != IXML_SUCCESS)
return NULL;
return attrNode; return attrNode;
} }
@ -403,7 +404,7 @@ int ixmlDocument_createCDATASectionEx(
ixmlCDATASection_init(cDSectionNode); ixmlCDATASection_init(cDSectionNode);
cDSectionNode->n.nodeType = eCDATA_SECTION_NODE; cDSectionNode->n.nodeType = eCDATA_SECTION_NODE;
cDSectionNode->n.nodeName = strdup(CDATANODENAME); cDSectionNode->n.nodeName = strdup((const char*)CDATANODENAME);
if (cDSectionNode->n.nodeName == NULL) { if (cDSectionNode->n.nodeName == NULL) {
ixmlCDATASection_free(cDSectionNode); ixmlCDATASection_free(cDSectionNode);
cDSectionNode = NULL; cDSectionNode = NULL;

View File

@ -431,7 +431,7 @@ int ixmlElement_setAttributeNS(
/* see DOM 2 spec page 59 */ /* see DOM 2 spec page 59 */
if ((newAttrNode.prefix != NULL && namespaceURI == NULL) || if ((newAttrNode.prefix != NULL && namespaceURI == NULL) ||
(strcmp(newAttrNode.prefix, "xml") == 0 && (newAttrNode.prefix != NULL && strcmp(newAttrNode.prefix, "xml") == 0 &&
strcmp(namespaceURI, "http://www.w3.org/XML/1998/namespace") != 0) || strcmp(namespaceURI, "http://www.w3.org/XML/1998/namespace") != 0) ||
(strcmp(qualifiedName, "xmlns") == 0 && (strcmp(qualifiedName, "xmlns") == 0 &&
strcmp(namespaceURI, "http://www.w3.org/2000/xmlns/") != 0)) { strcmp(namespaceURI, "http://www.w3.org/2000/xmlns/") != 0)) {

View File

@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -49,7 +50,7 @@
#define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) ) #define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) )
#define MEMBUF_DEF_SIZE_INC 20 #define MEMBUF_DEF_SIZE_INC 20u
/*! /*!

View File

@ -60,7 +60,7 @@ static void copy_with_escape(
if (p == NULL) if (p == NULL)
return; return;
plen = strlen(p); plen = strlen(p);
for (i = 0; i < plen; ++i) { for (i = (size_t)0; i < plen; ++i) {
switch (p[i]) { switch (p[i]) {
case '<': case '<':
ixml_membuf_append_str(buf, "&lt;"); ixml_membuf_append_str(buf, "&lt;");
@ -175,7 +175,7 @@ static void ixmlPrintDomTreeRecursive(
default: default:
IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive", IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive",
"Warning, unknown node type %d\n", "Warning, unknown node type %d\n",
ixmlNode_getNodeType(nodeptr)); (int)ixmlNode_getNodeType(nodeptr));
break; break;
} }
} }
@ -247,7 +247,7 @@ static void ixmlPrintDomTree(
default: default:
IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTree", IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTree",
"Warning, unknown node type %d\n", "Warning, unknown node type %d\n",
ixmlNode_getNodeType(nodeptr)); (int)ixmlNode_getNodeType(nodeptr));
break; break;
} }
} }
@ -318,7 +318,7 @@ static void ixmlDomTreetoString(
default: default:
IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive", IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive",
"Warning, unknown node type %d\n", "Warning, unknown node type %d\n",
ixmlNode_getNodeType(nodeptr)); (int)ixmlNode_getNodeType(nodeptr));
break; break;
} }
} }

View File

@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -87,11 +88,11 @@ static int ixml_membuf_set_size(
assert(alloc_len >= new_length); assert(alloc_len >= new_length);
temp_buf = realloc(m->buf, alloc_len + 1); temp_buf = realloc(m->buf, alloc_len + (size_t)1);
if (temp_buf == NULL) { if (temp_buf == NULL) {
/* try smaller size */ /* try smaller size */
alloc_len = new_length; alloc_len = new_length;
temp_buf = realloc(m->buf, alloc_len + 1); temp_buf = realloc(m->buf, alloc_len + (size_t)1);
if (temp_buf == NULL) { if (temp_buf == NULL) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
@ -110,8 +111,8 @@ void ixml_membuf_init(ixml_membuf *m)
m->size_inc = MEMBUF_DEF_SIZE_INC; m->size_inc = MEMBUF_DEF_SIZE_INC;
m->buf = NULL; m->buf = NULL;
m->length = 0; m->length = (size_t)0;
m->capacity = 0; m->capacity = (size_t)0;
} }
@ -171,7 +172,7 @@ int ixml_membuf_append(
{ {
assert(m != NULL); assert(m != NULL);
return ixml_membuf_insert(m, buf, 1, m->length); return ixml_membuf_insert(m, buf, (size_t)1, m->length);
} }
@ -197,7 +198,7 @@ int ixml_membuf_insert(
return IXML_INDEX_SIZE_ERR; return IXML_INDEX_SIZE_ERR;
} }
if (buf == NULL || buf_len == 0) { if (buf == NULL || buf_len == (size_t)0) {
return 0; return 0;
} }
/* alloc mem */ /* alloc mem */

View File

@ -410,7 +410,7 @@ static void Parser_skipWhiteSpaces(
Parser *xmlParser) Parser *xmlParser)
{ {
while( ( *( xmlParser->curPtr ) != 0 ) && while( ( *( xmlParser->curPtr ) != 0 ) &&
( strchr( WHITESPACE, *( xmlParser->curPtr ) ) != NULL ) ) { ( strchr( WHITESPACE, ( int ) *( xmlParser->curPtr ) ) != NULL ) ) {
xmlParser->curPtr++; xmlParser->curPtr++;
} }
} }
@ -694,12 +694,12 @@ static BOOL Parser_isNameChar(
/*! [in] TRUE if you also want to check in the NameChar table. */ /*! [in] TRUE if you also want to check in the NameChar table. */
BOOL bNameChar) BOOL bNameChar)
{ {
if (Parser_isCharInTable(c, Letter, LETTERTABLESIZE)) { if (Parser_isCharInTable(c, Letter, (int)LETTERTABLESIZE)) {
return TRUE; return TRUE;
} }
if (bNameChar && if (bNameChar &&
Parser_isCharInTable(c, NameChar, NAMECHARTABLESIZE)) { Parser_isCharInTable(c, NameChar, (int)NAMECHARTABLESIZE)) {
return TRUE; return TRUE;
} }
@ -746,7 +746,7 @@ static int Parser_getChar(
*cLen = 0; *cLen = 0;
if (*src != '&') { if (*src != '&') {
if (*src > 0 && Parser_isXmlChar(*src)) { if (*src > 0 && Parser_isXmlChar((int)*src)) {
*cLen = 1; *cLen = 1;
ret = *src; ret = *src;
goto ExitFunction; goto ExitFunction;
@ -763,30 +763,30 @@ static int Parser_getChar(
ret = i; ret = i;
goto ExitFunction; goto ExitFunction;
} else if (strncasecmp(src, QUOT, strlen(QUOT)) == 0) { } else if (strncasecmp(src, QUOT, strlen(QUOT)) == 0) {
*cLen = strlen(QUOT); *cLen = (int)strlen(QUOT);
ret = '"'; ret = '"';
goto ExitFunction; goto ExitFunction;
} else if (strncasecmp(src, LT, strlen(LT)) == 0) { } else if (strncasecmp(src, LT, strlen(LT)) == 0) {
*cLen = strlen(LT); *cLen = (int)strlen(LT);
ret = '<'; ret = '<';
goto ExitFunction; goto ExitFunction;
} else if (strncasecmp(src, GT, strlen(GT)) == 0) { } else if (strncasecmp(src, GT, strlen(GT)) == 0) {
*cLen = strlen(GT); *cLen = (int)strlen(GT);
ret = '>'; ret = '>';
goto ExitFunction; goto ExitFunction;
} else if (strncasecmp(src, APOS, strlen(APOS)) == 0) { } else if (strncasecmp(src, APOS, strlen(APOS)) == 0) {
*cLen = strlen(APOS); *cLen = (int)strlen(APOS);
ret = '\''; ret = '\'';
goto ExitFunction; goto ExitFunction;
} else if (strncasecmp(src, AMP, strlen(AMP)) == 0) { } else if (strncasecmp(src, AMP, strlen(AMP)) == 0) {
*cLen = strlen(AMP); *cLen = (int)strlen(AMP);
ret = '&'; ret = '&';
goto ExitFunction; goto ExitFunction;
} else if (strncasecmp(src, ESC_HEX, strlen(ESC_HEX)) == 0) { } else if (strncasecmp(src, ESC_HEX, strlen(ESC_HEX)) == 0) {
/* Read in escape characters of type &#xnn where nn is a hexadecimal value */ /* Read in escape characters of type &#xnn where nn is a hexadecimal value */
pnum = src + strlen( ESC_HEX ); pnum = src + strlen( ESC_HEX );
sum = 0; sum = 0;
while (strchr(HEX_NUMBERS, *pnum) != 0) { while (strchr(HEX_NUMBERS, (int)*pnum) != 0) {
c = *pnum; c = *pnum;
if (c <= '9') { if (c <= '9') {
sum = sum * 16 + ( c - '0' ); sum = sum * 16 + ( c - '0' );
@ -808,7 +808,7 @@ static int Parser_getChar(
/* Read in escape characters of type &#nn where nn is a decimal value */ /* Read in escape characters of type &#nn where nn is a decimal value */
pnum = src + strlen(ESC_DEC); pnum = src + strlen(ESC_DEC);
sum = 0; sum = 0;
while (strchr(DEC_NUMBERS, *pnum) != 0) { while (strchr(DEC_NUMBERS, (int)*pnum) != 0) {
sum = sum * 10 + ( *pnum - '0' ); sum = sum * 10 + ( *pnum - '0' );
pnum++; pnum++;
} }
@ -1224,7 +1224,7 @@ static int Parser_processCDSect(
pCDataStart = *pSrc + strlen( CDSTART ); pCDataStart = *pSrc + strlen( CDSTART );
pEnd = pCDataStart; pEnd = pCDataStart;
while( ( Parser_isXmlChar( *pEnd ) == TRUE ) && ( *pEnd != '\0' ) ) { while( ( Parser_isXmlChar( (int)*pEnd ) == TRUE ) && ( *pEnd != '\0' ) ) {
if( strncmp( pEnd, CDEND, strlen( CDEND ) ) == 0 ) { if( strncmp( pEnd, CDEND, strlen( CDEND ) ) == 0 ) {
break; break;
} else { } else {
@ -1233,8 +1233,8 @@ static int Parser_processCDSect(
} }
if( ( pEnd - pCDataStart > 0 ) && ( *pEnd != '\0' ) ) { if( ( pEnd - pCDataStart > 0 ) && ( *pEnd != '\0' ) ) {
tokenLength = (size_t)(pEnd - pCDataStart); tokenLength = (size_t)pEnd - (size_t)pCDataStart;
node->nodeValue = (char *)malloc(tokenLength + 1); node->nodeValue = (char *)malloc(tokenLength + (size_t)1);
if( node->nodeValue == NULL ) { if( node->nodeValue == NULL ) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
@ -1269,7 +1269,6 @@ static int Parser_processContent(
int ret = IXML_SUCCESS; int ret = IXML_SUCCESS;
int line = 0; int line = 0;
char *pEndContent; char *pEndContent;
BOOL bReadContent;
ptrdiff_t tokenLength; ptrdiff_t tokenLength;
const char *notAllowed = "]]>"; const char *notAllowed = "]]>";
char *pCurToken = NULL; char *pCurToken = NULL;
@ -1325,10 +1324,6 @@ static int Parser_processContent(
pEndContent++; pEndContent++;
} }
if (*pEndContent == '\0') {
bReadContent = FALSE;
}
if (strncmp(pEndContent, (const char *)notAllowed, strlen(notAllowed)) == 0) { if (strncmp(pEndContent, (const char *)notAllowed, strlen(notAllowed)) == 0) {
line = __LINE__; line = __LINE__;
ret = IXML_SYNTAX_ERR; ret = IXML_SYNTAX_ERR;
@ -1839,7 +1834,7 @@ static int Parser_getNextNode(
{ {
char *pCurToken = NULL; char *pCurToken = NULL;
char *lastElement = NULL; char *lastElement = NULL;
IXML_ERRORCODE ret = IXML_SUCCESS; int ret = IXML_SUCCESS;
int line = 0; int line = 0;
ptrdiff_t tokenLen = 0; ptrdiff_t tokenLen = 0;
@ -1851,7 +1846,7 @@ static int Parser_getNextNode(
goto ExitFunction; goto ExitFunction;
} }
if (xmlParser->state == eCONTENT) { if (xmlParser->state == (PARSER_STATE)eCONTENT) {
line = __LINE__; line = __LINE__;
ret = Parser_processContent(xmlParser, node); ret = Parser_processContent(xmlParser, node);
goto ExitFunction; goto ExitFunction;
@ -2214,7 +2209,7 @@ static int Parser_processElementName(
/* the node may have default namespace definition */ /* the node may have default namespace definition */
if (Parser_hasDefaultNamespace(xmlParser, newNode, &nsURI)) { if (Parser_hasDefaultNamespace(xmlParser, newNode, &nsURI)) {
Parser_setElementNamespace(newElement, nsURI); Parser_setElementNamespace(newElement, nsURI);
} else if (xmlParser->state == eATTRIBUTE) { } else if (xmlParser->state == (PARSER_STATE)eATTRIBUTE) {
/* the default namespace maybe defined later */ /* the default namespace maybe defined later */
xmlParser->pNeedPrefixNode = (IXML_Node *)newElement; xmlParser->pNeedPrefixNode = (IXML_Node *)newElement;
} }
@ -2297,7 +2292,7 @@ static int Parser_eTagVerification(
assert( newNode->nodeName ); assert( newNode->nodeName );
assert( xmlParser->currentNodePtr ); assert( xmlParser->currentNodePtr );
if( newNode->nodeType == eELEMENT_NODE ) { if( newNode->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE ) {
if( Parser_isValidEndElement( xmlParser, newNode ) == TRUE ) { if( Parser_isValidEndElement( xmlParser, newNode ) == TRUE ) {
Parser_popElement( xmlParser ); Parser_popElement( xmlParser );
} else { } else {
@ -2460,16 +2455,16 @@ ErrorHandler:
BOOL Parser_isValidXmlName(const DOMString name) BOOL Parser_isValidXmlName(const DOMString name)
{ {
const char *pstr = NULL; const char *pstr = NULL;
size_t i = 0; size_t i = (size_t)0;
size_t nameLen = 0; size_t nameLen = (size_t)0;
assert(name != NULL); assert(name != NULL);
nameLen = strlen(name); nameLen = strlen(name);
pstr = name; pstr = name;
if (Parser_isNameChar(*pstr, FALSE) == TRUE) { if (Parser_isNameChar((int)*pstr, FALSE) == TRUE) {
for (i = 1; i < nameLen; ++i) { for (i = (size_t)1; i < nameLen; ++i) {
if (Parser_isNameChar(*(pstr + i), TRUE) == FALSE) { if (Parser_isNameChar((int)*(pstr + i), TRUE) == FALSE) {
/* illegal char */ /* illegal char */
return FALSE; return FALSE;
} }
@ -2501,6 +2496,12 @@ static Parser *Parser_init()
} }
memset(newParser, 0, sizeof (Parser)); memset(newParser, 0, sizeof (Parser));
newParser->dataBuffer = NULL;
newParser->curPtr = NULL;
newParser->savePtr = NULL;
newParser->pNeedPrefixNode = NULL;
newParser->pCurElement = NULL;
newParser->currentNodePtr = NULL;
ixml_membuf_init(&(newParser->tokenBuf)); ixml_membuf_init(&(newParser->tokenBuf));
ixml_membuf_init(&(newParser->lastElem)); ixml_membuf_init(&(newParser->lastElem));
@ -2545,7 +2546,7 @@ static int Parser_readFileOrBuffer(
fseek( xmlFilePtr, 0, SEEK_SET ); fseek( xmlFilePtr, 0, SEEK_SET );
bytesRead = bytesRead =
fread(xmlParser->dataBuffer, 1, (size_t)fileSize, xmlFilePtr); fread(xmlParser->dataBuffer, (size_t)1, (size_t)fileSize, xmlFilePtr);
/* append null */ /* append null */
xmlParser->dataBuffer[bytesRead] = '\0'; xmlParser->dataBuffer[bytesRead] = '\0';
fclose( xmlFilePtr ); fclose( xmlFilePtr );
@ -2652,12 +2653,12 @@ int Parser_setNodePrefixAndLocalName(
/* fill in the local name and prefix */ /* fill in the local name and prefix */
pLocalName = ( char * )pStrPrefix + 1; pLocalName = ( char * )pStrPrefix + 1;
nPrefix = pStrPrefix - node->nodeName; nPrefix = pStrPrefix - node->nodeName;
node->prefix = malloc((size_t)nPrefix + 1); node->prefix = malloc((size_t)nPrefix + (size_t)1);
if (!node->prefix) { if (!node->prefix) {
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;
} }
memset(node->prefix, 0, (size_t)nPrefix + 1); memset(node->prefix, 0, (size_t)nPrefix + (size_t)1);
strncpy(node->prefix, node->nodeName, (size_t)nPrefix); strncpy(node->prefix, node->nodeName, (size_t)nPrefix);
node->localName = safe_strdup( pLocalName ); node->localName = safe_strdup( pLocalName );

View File

@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -53,11 +54,11 @@ static unsigned long ixmlNamedNodeMap_getItemNumber(
IN const char *name) IN const char *name)
{ {
IXML_Node *tempNode; IXML_Node *tempNode;
unsigned long returnItemNo = 0; unsigned long returnItemNo = 0lu;
assert(nnMap != NULL && name != NULL); assert(nnMap != NULL && name != NULL);
if (nnMap == NULL || name == NULL) { if (nnMap == NULL || name == NULL) {
return IXML_INVALID_ITEM_NUMBER; return (unsigned long)IXML_INVALID_ITEM_NUMBER;
} }
tempNode = nnMap->nodeItem; tempNode = nnMap->nodeItem;
@ -69,7 +70,7 @@ static unsigned long ixmlNamedNodeMap_getItemNumber(
returnItemNo++; returnItemNo++;
} }
return IXML_INVALID_ITEM_NUMBER; return (unsigned long)IXML_INVALID_ITEM_NUMBER;
} }
@ -92,7 +93,7 @@ IXML_Node *ixmlNamedNodeMap_getNamedItem(
} }
index = ixmlNamedNodeMap_getItemNumber(nnMap, name); index = ixmlNamedNodeMap_getItemNumber(nnMap, name);
if (index == IXML_INVALID_ITEM_NUMBER) { if (index == (unsigned long)IXML_INVALID_ITEM_NUMBER) {
return NULL; return NULL;
} else { } else {
return ixmlNamedNodeMap_item(nnMap, index); return ixmlNamedNodeMap_item(nnMap, index);
@ -111,12 +112,12 @@ IXML_Node *ixmlNamedNodeMap_item(
return NULL; return NULL;
} }
if (index > ixmlNamedNodeMap_getLength(nnMap) - 1) { if (index > ixmlNamedNodeMap_getLength(nnMap) - 1lu) {
return NULL; return NULL;
} }
tempNode = nnMap->nodeItem; tempNode = nnMap->nodeItem;
for (i = 0; i < index && tempNode != NULL; ++i) { for (i = 0u; i < index && tempNode != NULL; ++i) {
tempNode = tempNode->nextSibling; tempNode = tempNode->nextSibling;
} }
@ -131,7 +132,7 @@ unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
if (nnMap != NULL) { if (nnMap != NULL) {
tempNode = nnMap->nodeItem; tempNode = nnMap->nodeItem;
for (length = 0; tempNode != NULL; ++length) { for (length = 0lu; tempNode != NULL; ++length) {
tempNode = tempNode->nextSibling; tempNode = tempNode->nextSibling;
} }
} }

View File

@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -48,6 +49,12 @@ void ixmlNode_init(IXML_Node *nodeptr)
assert(nodeptr != NULL); assert(nodeptr != NULL);
memset(nodeptr, 0, sizeof (IXML_Node)); memset(nodeptr, 0, sizeof (IXML_Node));
nodeptr->parentNode = NULL;
nodeptr->firstChild = NULL;
nodeptr->prevSibling = NULL;
nodeptr->nextSibling = NULL;
nodeptr->firstAttr = NULL;
nodeptr->ownerDocument = NULL;
} }
@ -90,7 +97,7 @@ static void ixmlNode_freeSingleNode(
if (nodeptr->localName != NULL) { if (nodeptr->localName != NULL) {
free(nodeptr->localName); free(nodeptr->localName);
} }
if (nodeptr->nodeType == eELEMENT_NODE) { if (nodeptr->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE) {
element = (IXML_Element *)nodeptr; element = (IXML_Element *)nodeptr;
free(element->tagName); free(element->tagName);
} }
@ -280,7 +287,7 @@ unsigned short ixmlNode_getNodeType(IXML_Node *nodeptr)
if (nodeptr != NULL) { if (nodeptr != NULL) {
return nodeptr->nodeType; return nodeptr->nodeType;
} else { } else {
return eINVALID_NODE; return (unsigned short)eINVALID_NODE;
} }
} }
@ -397,7 +404,8 @@ static BOOL ixmlNode_isParent(
assert(nodeptr != NULL && toFind != NULL); assert(nodeptr != NULL && toFind != NULL);
found = toFind->parentNode == nodeptr; if (nodeptr != NULL && toFind != NULL)
found = toFind->parentNode == nodeptr;
return found; return found;
} }
@ -425,14 +433,14 @@ static BOOL ixmlNode_allowChildren(
break; break;
case eELEMENT_NODE: case eELEMENT_NODE:
if (newChild->nodeType == eATTRIBUTE_NODE || if (newChild->nodeType == (IXML_NODE_TYPE)eATTRIBUTE_NODE ||
newChild->nodeType == eDOCUMENT_NODE) { newChild->nodeType == (IXML_NODE_TYPE)eDOCUMENT_NODE) {
return FALSE; return FALSE;
} }
break; break;
case eDOCUMENT_NODE: case eDOCUMENT_NODE:
if (newChild->nodeType != eELEMENT_NODE) { if (newChild->nodeType != (IXML_NODE_TYPE)eELEMENT_NODE) {
return FALSE; return FALSE;
} }
@ -915,6 +923,8 @@ static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
switch (nodeptr->nodeType) { switch (nodeptr->nodeType) {
case eELEMENT_NODE: case eELEMENT_NODE:
newElement = ixmlNode_cloneElement((IXML_Element *)nodeptr); newElement = ixmlNode_cloneElement((IXML_Element *)nodeptr);
if (newElement == NULL)
return NULL;
newElement->n.firstAttr = ixmlNode_cloneNodeTreeRecursive( newElement->n.firstAttr = ixmlNode_cloneNodeTreeRecursive(
nodeptr->firstAttr, deep); nodeptr->firstAttr, deep);
if (deep) { if (deep) {
@ -935,6 +945,8 @@ static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
case eATTRIBUTE_NODE: case eATTRIBUTE_NODE:
newAttr = ixmlNode_cloneAttr((IXML_Attr *)nodeptr); newAttr = ixmlNode_cloneAttr((IXML_Attr *)nodeptr);
if (newAttr == NULL)
return NULL;
nextSib = ixmlNode_cloneNodeTreeRecursive(nodeptr->nextSibling, deep); nextSib = ixmlNode_cloneNodeTreeRecursive(nodeptr->nextSibling, deep);
newAttr->n.nextSibling = nextSib; newAttr->n.nextSibling = nextSib;
if (nextSib != NULL) { if (nextSib != NULL) {
@ -954,6 +966,8 @@ static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
case eDOCUMENT_NODE: case eDOCUMENT_NODE:
newDoc = ixmlNode_cloneDoc((IXML_Document *)nodeptr); newDoc = ixmlNode_cloneDoc((IXML_Document *)nodeptr);
if (newDoc == NULL)
return NULL;
newNode = (IXML_Node *)newDoc; newNode = (IXML_Node *)newDoc;
if (deep) { if (deep) {
newNode->firstChild = ixmlNode_cloneNodeTreeRecursive( newNode->firstChild = ixmlNode_cloneNodeTreeRecursive(
@ -1000,6 +1014,8 @@ static IXML_Node *ixmlNode_cloneNodeTree(
switch (nodeptr->nodeType) { switch (nodeptr->nodeType) {
case eELEMENT_NODE: case eELEMENT_NODE:
newElement = ixmlNode_cloneElement((IXML_Element *)nodeptr); newElement = ixmlNode_cloneElement((IXML_Element *)nodeptr);
if (newElement == NULL)
return NULL;
newElement->n.firstAttr = ixmlNode_cloneNodeTreeRecursive(nodeptr->firstAttr, deep); newElement->n.firstAttr = ixmlNode_cloneNodeTreeRecursive(nodeptr->firstAttr, deep);
if (deep) { if (deep) {
newElement->n.firstChild = ixmlNode_cloneNodeTreeRecursive( newElement->n.firstChild = ixmlNode_cloneNodeTreeRecursive(
@ -1112,7 +1128,7 @@ IXML_NamedNodeMap *ixmlNode_getAttributes(IXML_Node *nodeptr)
return NULL; return NULL;
} }
if(nodeptr->nodeType == eELEMENT_NODE) { if(nodeptr->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE) {
returnNamedNodeMap = (IXML_NamedNodeMap *)malloc(sizeof(IXML_NamedNodeMap)); returnNamedNodeMap = (IXML_NamedNodeMap *)malloc(sizeof(IXML_NamedNodeMap));
if(returnNamedNodeMap == NULL) { if(returnNamedNodeMap == NULL) {
return NULL; return NULL;
@ -1150,7 +1166,8 @@ BOOL ixmlNode_hasChildNodes(IXML_Node *nodeptr)
BOOL ixmlNode_hasAttributes(IXML_Node *nodeptr) BOOL ixmlNode_hasAttributes(IXML_Node *nodeptr)
{ {
if (nodeptr != NULL) { if (nodeptr != NULL) {
if (nodeptr->nodeType == eELEMENT_NODE && nodeptr->firstAttr != NULL) { if (nodeptr->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE &&
nodeptr->firstAttr != NULL) {
return TRUE; return TRUE;
} }
} }

View File

@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -62,12 +63,12 @@ IXML_Node *ixmlNodeList_item(
return NULL; return NULL;
} }
/* if index is more than list length */ /* if index is more than list length */
if (index > ixmlNodeList_length(nList) - 1) { if (index > ixmlNodeList_length(nList) - 1lu) {
return NULL; return NULL;
} }
next = nList; next = nList;
for (i = 0; i < index && next != NULL; ++i) { for (i = 0u; i < index && next != NULL; ++i) {
next = next->next; next = next->next;
} }
@ -127,7 +128,7 @@ int ixmlNodeList_addToNodeList(
unsigned long ixmlNodeList_length(IXML_NodeList *nList) unsigned long ixmlNodeList_length(IXML_NodeList *nList)
{ {
IXML_NodeList *list; IXML_NodeList *list;
unsigned long length = 0; unsigned long length = 0lu;
list = nList; list = nList;
while (list != NULL) { while (list != NULL) {