diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2006-03-09 18:41:40 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2006-03-09 18:41:40 +0000 |
commit | 14b5643947845df089376106517c4f7ba061e4b0 (patch) | |
tree | 7afe83d4439da85a3e31ebc5bfd621a6c750326d | |
parent | 2728f845c5581af9213057ace8b3f664d64c15a9 (diff) | |
download | libxml2-14b5643947845df089376106517c4f7ba061e4b0.tar.gz |
more cleanups based on coverity reports. Daniel
* relaxng.c xmlschemas.c xmlschemastypes.c: more cleanups based
on coverity reports.
Daniel
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | relaxng.c | 44 | ||||
-rw-r--r-- | xmlschemas.c | 29 | ||||
-rw-r--r-- | xmlschemastypes.c | 17 |
4 files changed, 60 insertions, 35 deletions
@@ -1,3 +1,8 @@ +Thu Mar 9 19:36:14 CET 2006 Daniel Veillard <daniel@veillard.com> + + * relaxng.c xmlschemas.c xmlschemastypes.c: more cleanups based + on coverity reports. + Thu Mar 9 17:47:40 CET 2006 Daniel Veillard <daniel@veillard.com> * SAX2.c catalog.c encoding.c entities.c example/gjobread.c @@ -1159,7 +1159,7 @@ xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt, ctxt->freeStates = tmp; ctxt->freeStatesMax *= 2; } - if ((ctxt == NULL) || (ctxt->freeState == NULL)) { + if ((ctxt == NULL) || (ctxt->freeStates == NULL)) { xmlFree(states->tabState); xmlFree(states); } else { @@ -1563,8 +1563,10 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt, children, name) == 1) { found = 1; } +#ifdef DEBUG_INCLUDE if (href != NULL) xmlFree(href); +#endif } } } @@ -3577,7 +3579,7 @@ xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) static xmlRelaxNGDefinePtr xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) { - xmlRelaxNGDefinePtr def = NULL, except, last = NULL; + xmlRelaxNGDefinePtr def = NULL, except; xmlRelaxNGDefinePtr param, lastparam = NULL; xmlRelaxNGTypeLibraryPtr lib; xmlChar *type; @@ -3685,7 +3687,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) if ((content != NULL) && (xmlStrEqual(content->name, BAD_CAST "except"))) { xmlNodePtr child; - xmlRelaxNGDefinePtr tmp2, last2 = NULL; + xmlRelaxNGDefinePtr tmp2, last = NULL; except = xmlRelaxNGNewDefine(ctxt, node); if (except == NULL) { @@ -3693,11 +3695,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) } except->type = XML_RELAXNG_EXCEPT; child = content->children; - if (last == NULL) { - def->content = except; - } else { - last->next = except; - } + def->content = except; if (child == NULL) { xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT, "except has no content\n", NULL, NULL); @@ -3705,11 +3703,11 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) while (child != NULL) { tmp2 = xmlRelaxNGParsePattern(ctxt, child); if (tmp2 != NULL) { - if (last2 == NULL) { - except->content = last2 = tmp2; + if (last == NULL) { + except->content = last = tmp2; } else { - last2->next = tmp2; - last2 = tmp2; + last->next = tmp2; + last = tmp2; } } child = child->next; @@ -7796,8 +7794,6 @@ xmlRelaxNGValidateCompiledCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED, #endif if (ctxt == NULL) { fprintf(stderr, "callback on %s missing context\n", token); - if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK)) - ctxt->errNo = XML_RELAXNG_ERR_INTERNAL; return; } if (define == NULL) { @@ -7841,10 +7837,11 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt, xmlRegExecCtxtPtr exec; xmlNodePtr cur; int ret = 0; - int oldperr = ctxt->perr; + int oldperr; if ((ctxt == NULL) || (regexp == NULL)) return (-1); + oldperr = ctxt->perr; exec = xmlRegNewExecCtxt(regexp, xmlRelaxNGValidateCompiledCallback, ctxt); ctxt->perr = 0; @@ -8003,7 +8000,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata; xmlRelaxNGDefinePtr define = (xmlRelaxNGDefinePtr) transdata; xmlRelaxNGValidStatePtr state, oldstate; - xmlNodePtr node = ctxt->pnode; + xmlNodePtr node; int ret = 0, oldflags; #ifdef DEBUG_PROGRESSIVE @@ -8014,6 +8011,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec fprintf(stderr, "callback on %s missing context\n", token); return; } + node = ctxt->pnode; ctxt->pstate = 1; if (define == NULL) { if (token[0] == '#') @@ -8767,13 +8765,8 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, cur = ctxt->state->value; } ctxt->flags = oldflags; - if (ret != 0) { - if ((ctxt->flags & FLAGS_IGNORABLE) == 0) - xmlRelaxNGDumpValidError(ctxt); - } else { - if (ctxt->errNr > 0) - xmlRelaxNGPopErrors(ctxt, 0); - } + if (ctxt->errNr > 0) + xmlRelaxNGPopErrors(ctxt, 0); break; } case XML_RELAXNG_EXCEPT:{ @@ -10091,6 +10084,11 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt, if (states == NULL) { xmlRelaxNGNewStates(ctxt, res->nbState - base); + states = ctxt->states; + if (states == NULL) { + progress = 0; + break; + } } states->nbState = 0; for (i = base; i < res->nbState; i++) diff --git a/xmlschemas.c b/xmlschemas.c index 56f9a441..d8824de7 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -2232,6 +2232,8 @@ xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt, { xmlChar *msg = NULL; + if (actxt == NULL) + return; msg = xmlStrdup(BAD_CAST "Internal error: "); msg = xmlStrcat(msg, BAD_CAST funcName); msg = xmlStrcat(msg, BAD_CAST ", "); @@ -2820,9 +2822,15 @@ xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, des = *ownerDes; } else des = *ownerDes; - xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, - "%s, attribute '%s': %s.\n", - BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); + if (attr == NULL) { + xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL, + "%s, attribute '%s': %s.\n", + BAD_CAST des, "Unknown", (const xmlChar *) msg, NULL, NULL); + } else { + xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, + "%s, attribute '%s': %s.\n", + BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); + } if (ownerDes == NULL) FREE_AND_NULL(des); } @@ -7991,7 +7999,10 @@ xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, * TODO: Call xmlPatterncompile with different options for selector/ * field. */ - nsList = xmlGetNsList(attr->doc, attr->parent); + if (attr == NULL) + nsList == NULL; + else + nsList = xmlGetNsList(attr->doc, attr->parent); /* * Build an array of prefixes and namespaces. */ @@ -15505,8 +15516,7 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt, if (baseMember == NULL) { PERROR_INT("xmlSchemaCheckCOSSTRestricts", "different number of member types in base"); - } - if ((member->type != baseMember->type) && + } else if ((member->type != baseMember->type) && (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, member->type, baseMember->type, 0) != 0)) { xmlChar *strBMT = NULL, *strBT = NULL; @@ -24592,7 +24602,7 @@ static int xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt) { xmlSchemaElementPtr elemDecl = vctxt->inode->decl; - xmlSchemaTypePtr actualType = WXS_ELEM_TYPEDEF(elemDecl); + xmlSchemaTypePtr actualType; /* * cvc-elt (3.3.4) : 1 @@ -24602,6 +24612,7 @@ xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt) "No matching declaration available"); return (vctxt->err); } + actualType = WXS_ELEM_TYPEDEF(elemDecl); /* * cvc-elt (3.3.4) : 2 */ @@ -27460,7 +27471,7 @@ xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt) /* * Process character content. */ - if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) + if ((ielem != NULL) && (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)) ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY; ret = xmlSchemaVPushText(vctxt, node->type, node->content, -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL); @@ -27991,6 +28002,8 @@ static void referenceSplit(void *ctx, const xmlChar *name) { xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; + if (ctxt == NULL) + return; if ((ctxt != NULL) && (ctxt->user_sax != NULL) && (ctxt->user_sax->reference != NULL)) ctxt->user_sax->reference(ctxt->user_data, name); diff --git a/xmlschemastypes.c b/xmlschemastypes.c index 557d0ab2..987f85ff 100644 --- a/xmlschemastypes.c +++ b/xmlschemastypes.c @@ -237,6 +237,9 @@ xmlSchemaNewMinLengthFacet(int value) xmlSchemaFacetPtr ret; ret = xmlSchemaNewFacet(); + if (ret == NULL) { + return(NULL); + } ret->type = XML_SCHEMA_FACET_MINLENGTH; ret->val = xmlSchemaNewValue(XML_SCHEMAS_NNINTEGER); ret->val->value.decimal.lo = value; @@ -1390,11 +1393,12 @@ _xmlSchemaParseTime (xmlSchemaValDatePtr dt, const xmlChar **str) { */ static int _xmlSchemaParseTimeZone (xmlSchemaValDatePtr dt, const xmlChar **str) { - const xmlChar *cur = *str; + const xmlChar *cur; int ret = 0; if (str == NULL) return -1; + cur = *str; switch (*cur) { case 0: @@ -2386,9 +2390,6 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value, const xmlChar *cur = value; int neg = 0; - if (cur == NULL) - goto return1; - if (normOnTheFly) while IS_WSP_BLANK_CH(*cur) cur++; @@ -3818,6 +3819,14 @@ _xmlSchemaDateAdd (xmlSchemaValPtr dt, xmlSchemaValPtr dur) long tyr = r->year + (long)FQUOTIENT_RANGE((int)r->mon-1, 1, 13); if (tyr == 0) tyr--; + /* + * Coverity detected an overrun in daysInMonth + * of size 12 at position 12 with index variable "((r)->mon - 1)" + */ + if (tmon < 0) + tmon = 0; + if (tmon > 12) + tmon = 12; tempdays += MAX_DAYINMONTH(tyr, tmon); carry = -1; } else if (tempdays > (long) MAX_DAYINMONTH(r->year, r->mon)) { |