diff --git a/ChangeLog b/ChangeLog index 1e667ccb..16ba20a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Mar 9 17:47:40 CET 2006 Daniel Veillard + + * SAX2.c catalog.c encoding.c entities.c example/gjobread.c + python/libxml.c: more cleanups based on coverity reports. + Thu Mar 9 15:12:19 CET 2006 Daniel Veillard * HTMLparser.c parser.c parserInternals.c pattern.c uri.c: a bunch diff --git a/SAX2.c b/SAX2.c index 17425e7e..75d5f4c4 100644 --- a/SAX2.c +++ b/SAX2.c @@ -83,15 +83,21 @@ xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error, ctxt->errNo = error; if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) schannel = ctxt->sax->serror; - } - __xmlRaiseError(schannel, - ctxt->vctxt.error, ctxt->vctxt.userData, - ctxt, NULL, XML_FROM_DTD, error, - XML_ERR_ERROR, NULL, 0, (const char *) str1, - (const char *) str2, NULL, 0, 0, - msg, (const char *) str1, (const char *) str2); - if (ctxt != NULL) + __xmlRaiseError(schannel, + ctxt->vctxt.error, ctxt->vctxt.userData, + ctxt, NULL, XML_FROM_DTD, error, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + (const char *) str2, NULL, 0, 0, + msg, (const char *) str1, (const char *) str2); ctxt->valid = 0; + } else { + __xmlRaiseError(schannel, + NULL, NULL, + ctxt, NULL, XML_FROM_DTD, error, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + (const char *) str2, NULL, 0, 0, + msg, (const char *) str1, (const char *) str2); + } } /** @@ -694,7 +700,9 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, xmlAttributePtr attr; xmlChar *name = NULL, *prefix = NULL; - if (ctx == NULL) return; + if ((ctxt == NULL) || (ctxt->myDoc == NULL)) + return; + #ifdef DEBUG_SAX xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n", @@ -732,7 +740,7 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, if (ctxt->vctxt.valid == 0) ctxt->valid = 0; if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) && - (ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset != NULL)) + (ctxt->myDoc->intSubset != NULL)) ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, attr); #endif /* LIBXML_VALID_ENABLED */ @@ -758,7 +766,9 @@ xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type, xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlElementPtr elem = NULL; - if (ctx == NULL) return; + if ((ctxt == NULL) || (ctxt->myDoc == NULL)) + return; + #ifdef DEBUG_SAX xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type); @@ -802,7 +812,9 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name, xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNotationPtr nota = NULL; - if (ctx == NULL) return; + if ((ctxt == NULL) || (ctxt->myDoc == NULL)) + return; + #ifdef DEBUG_SAX xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId); @@ -827,8 +839,8 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name, } #ifdef LIBXML_VALID_ENABLED if (nota == NULL) ctxt->valid = 0; - if (ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) + if ((ctxt->validate) && (ctxt->wellFormed) && + (ctxt->myDoc->intSubset != NULL)) ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc, nota); #endif /* LIBXML_VALID_ENABLED */ diff --git a/catalog.c b/catalog.c index 7aea5714..5456094d 100644 --- a/catalog.c +++ b/catalog.c @@ -1200,8 +1200,6 @@ static void xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer, xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup) { - xmlChar *uri = NULL; - xmlChar *URL = NULL; xmlChar *base = NULL; xmlCatalogEntryPtr entry = NULL; @@ -1288,10 +1286,6 @@ xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer, } if (base != NULL) xmlFree(base); - if (uri != NULL) - xmlFree(uri); - if (URL != NULL) - xmlFree(URL); } /** @@ -3220,7 +3214,7 @@ xmlLoadCatalogs(const char *pathss) { return; cur = pathss; - while ((cur != NULL) && (*cur != 0)) { + while (*cur != 0) { while (xmlIsBlank_ch(*cur)) cur++; if (*cur != 0) { paths = cur; diff --git a/encoding.c b/encoding.c index c6cfe919..7fa97d90 100644 --- a/encoding.c +++ b/encoding.c @@ -132,21 +132,16 @@ asciiToUTF8(unsigned char* out, int *outlen, while ((in < inend) && (out - outstart + 5 < *outlen)) { c= *in++; - /* assertion: c is a single UTF-4 value */ if (out >= outend) break; - if (c < 0x80) { *out++= c; bits= -6; } - else { + if (c < 0x80) { + *out++ = c; + } else { *outlen = out - outstart; *inlen = processed - base; return(-1); } - for ( ; bits >= 0; bits-= 6) { - if (out >= outend) - break; - *out++= ((c >> bits) & 0x3F) | 0x80; - } processed = (const unsigned char*) in; } *outlen = out - outstart; @@ -529,7 +524,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen, const unsigned char *const instart = in; unsigned short* outstart= out; unsigned short* outend; - const unsigned char* inend= in+*inlen; + const unsigned char* inend; unsigned int c, d; int trailing; unsigned char *tmp; @@ -542,6 +537,7 @@ UTF8ToUTF16LE(unsigned char* outb, int *outlen, *inlen = 0; return(0); } + inend= in + *inlen; outend = out + (*outlen / 2); while (in < inend) { d= *in++; @@ -770,7 +766,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen, const unsigned char *const instart = in; unsigned short* outstart= out; unsigned short* outend; - const unsigned char* inend= in+*inlen; + const unsigned char* inend; unsigned int c, d; int trailing; unsigned char *tmp; @@ -783,6 +779,7 @@ UTF8ToUTF16BE(unsigned char* outb, int *outlen, *inlen = 0; return(0); } + inend= in + *inlen; outend = out + (*outlen / 2); while (in < inend) { d= *in++; @@ -1702,13 +1699,8 @@ xmlIconvWrapper(iconv_t cd, unsigned char *out, int *outlen, icv_inlen = *inlen; icv_outlen = *outlen; ret = iconv(cd, (char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen); - if (in != NULL) { - *inlen -= icv_inlen; - *outlen -= icv_outlen; - } else { - *inlen = 0; - *outlen = 0; - } + *inlen -= icv_inlen; + *outlen -= icv_outlen; if ((icv_inlen != 0) || (ret == -1)) { #ifdef EILSEQ if (errno == EILSEQ) { diff --git a/entities.c b/entities.c index 08034c35..6a0e38d7 100644 --- a/entities.c +++ b/entities.c @@ -560,7 +560,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { *out++ = xc; } else */ - *out++ = *cur; + *out++ = *cur; } else { /* * We assume we have UTF-8 input. @@ -616,10 +616,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { /* * We could do multiple things here. Just save as a char ref */ - if (html) - snprintf(buf, sizeof(buf), "&#%d;", val); - else - snprintf(buf, sizeof(buf), "&#x%X;", val); + snprintf(buf, sizeof(buf), "&#x%X;", val); buf[sizeof(buf) - 1] = 0; ptr = buf; while (*ptr != 0) *out++ = *ptr++; diff --git a/example/gjobread.c b/example/gjobread.c index b192bf4f..d3f6d57d 100644 --- a/example/gjobread.c +++ b/example/gjobread.c @@ -237,12 +237,14 @@ parseGjobFile(char *filename) { */ /* First level we expect just Jobs */ cur = cur->xmlChildrenNode; - while ( cur && xmlIsBlankNode ( cur ) ) - { + while ( cur && xmlIsBlankNode ( cur ) ) { cur = cur -> next; - } - if ( cur == 0 ) - return ( NULL ); + } + if ( cur == 0 ) { + xmlFreeDoc(doc); + free(ret); + return ( NULL ); + } if ((xmlStrcmp(cur->name, (const xmlChar *) "Jobs")) || (cur->ns != ns)) { fprintf(stderr,"document of the wrong type, was '%s', Jobs expected", cur->name); diff --git a/python/libxml.c b/python/libxml.c index ad8ac7c6..88b29cf0 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -2323,13 +2323,13 @@ static PyObject * libxml_properties(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; - xmlNodePtr cur = NULL; + xmlNodePtr cur; xmlAttrPtr res; if (!PyArg_ParseTuple(args, (char *) "O:properties", &obj)) return NULL; cur = PyxmlNode_Get(obj); - if (cur->type == XML_ELEMENT_NODE) + if ((cur != NULL) && (cur->type == XML_ELEMENT_NODE)) res = cur->properties; else res = NULL;