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
*******************************************************************************
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>
Exclude IPv6 stuff in SearchByTarget when UPNP_ENABLE_IPV6 is not defined.

View File

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

View File

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

View File

@ -431,7 +431,7 @@ int ixmlElement_setAttributeNS(
/* see DOM 2 spec page 59 */
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(qualifiedName, "xmlns") == 0 &&
strcmp(namespaceURI, "http://www.w3.org/2000/xmlns/") != 0)) {

View File

@ -2,6 +2,7 @@
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -49,7 +50,7 @@
#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)
return;
plen = strlen(p);
for (i = 0; i < plen; ++i) {
for (i = (size_t)0; i < plen; ++i) {
switch (p[i]) {
case '<':
ixml_membuf_append_str(buf, "&lt;");
@ -175,7 +175,7 @@ static void ixmlPrintDomTreeRecursive(
default:
IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive",
"Warning, unknown node type %d\n",
ixmlNode_getNodeType(nodeptr));
(int)ixmlNode_getNodeType(nodeptr));
break;
}
}
@ -247,7 +247,7 @@ static void ixmlPrintDomTree(
default:
IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTree",
"Warning, unknown node type %d\n",
ixmlNode_getNodeType(nodeptr));
(int)ixmlNode_getNodeType(nodeptr));
break;
}
}
@ -318,7 +318,7 @@ static void ixmlDomTreetoString(
default:
IxmlPrintf(__FILE__, __LINE__, "ixmlPrintDomTreeRecursive",
"Warning, unknown node type %d\n",
ixmlNode_getNodeType(nodeptr));
(int)ixmlNode_getNodeType(nodeptr));
break;
}
}

View File

@ -2,6 +2,7 @@
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* 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);
temp_buf = realloc(m->buf, alloc_len + 1);
temp_buf = realloc(m->buf, alloc_len + (size_t)1);
if (temp_buf == NULL) {
/* try smaller size */
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) {
return IXML_INSUFFICIENT_MEMORY;
}
@ -110,8 +111,8 @@ void ixml_membuf_init(ixml_membuf *m)
m->size_inc = MEMBUF_DEF_SIZE_INC;
m->buf = NULL;
m->length = 0;
m->capacity = 0;
m->length = (size_t)0;
m->capacity = (size_t)0;
}
@ -171,7 +172,7 @@ int ixml_membuf_append(
{
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;
}
if (buf == NULL || buf_len == 0) {
if (buf == NULL || buf_len == (size_t)0) {
return 0;
}
/* alloc mem */

View File

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

View File

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

View File

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

View File

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