Commit 14b56439 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

more cleanups based on coverity reports. Daniel

* relaxng.c xmlschemas.c xmlschemastypes.c: more cleanups based
  on coverity reports.
Daniel
parent 2728f845
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> Thu Mar 9 17:47:40 CET 2006 Daniel Veillard <daniel@veillard.com>
* SAX2.c catalog.c encoding.c entities.c example/gjobread.c * SAX2.c catalog.c encoding.c entities.c example/gjobread.c
......
...@@ -1159,7 +1159,7 @@ xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt, ...@@ -1159,7 +1159,7 @@ xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt,
ctxt->freeStates = tmp; ctxt->freeStates = tmp;
ctxt->freeStatesMax *= 2; ctxt->freeStatesMax *= 2;
} }
if ((ctxt == NULL) || (ctxt->freeState == NULL)) { if ((ctxt == NULL) || (ctxt->freeStates == NULL)) {
xmlFree(states->tabState); xmlFree(states->tabState);
xmlFree(states); xmlFree(states);
} else { } else {
...@@ -1563,8 +1563,10 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt, ...@@ -1563,8 +1563,10 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
children, name) == 1) { children, name) == 1) {
found = 1; found = 1;
} }
#ifdef DEBUG_INCLUDE
if (href != NULL) if (href != NULL)
xmlFree(href); xmlFree(href);
#endif
} }
} }
} }
...@@ -3577,7 +3579,7 @@ xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) ...@@ -3577,7 +3579,7 @@ xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
static xmlRelaxNGDefinePtr static xmlRelaxNGDefinePtr
xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
{ {
xmlRelaxNGDefinePtr def = NULL, except, last = NULL; xmlRelaxNGDefinePtr def = NULL, except;
xmlRelaxNGDefinePtr param, lastparam = NULL; xmlRelaxNGDefinePtr param, lastparam = NULL;
xmlRelaxNGTypeLibraryPtr lib; xmlRelaxNGTypeLibraryPtr lib;
xmlChar *type; xmlChar *type;
...@@ -3685,7 +3687,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) ...@@ -3685,7 +3687,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
if ((content != NULL) if ((content != NULL)
&& (xmlStrEqual(content->name, BAD_CAST "except"))) { && (xmlStrEqual(content->name, BAD_CAST "except"))) {
xmlNodePtr child; xmlNodePtr child;
xmlRelaxNGDefinePtr tmp2, last2 = NULL; xmlRelaxNGDefinePtr tmp2, last = NULL;
except = xmlRelaxNGNewDefine(ctxt, node); except = xmlRelaxNGNewDefine(ctxt, node);
if (except == NULL) { if (except == NULL) {
...@@ -3693,11 +3695,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) ...@@ -3693,11 +3695,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
} }
except->type = XML_RELAXNG_EXCEPT; except->type = XML_RELAXNG_EXCEPT;
child = content->children; child = content->children;
if (last == NULL) { def->content = except;
def->content = except;
} else {
last->next = except;
}
if (child == NULL) { if (child == NULL) {
xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT, xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT,
"except has no content\n", NULL, NULL); "except has no content\n", NULL, NULL);
...@@ -3705,11 +3703,11 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) ...@@ -3705,11 +3703,11 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
while (child != NULL) { while (child != NULL) {
tmp2 = xmlRelaxNGParsePattern(ctxt, child); tmp2 = xmlRelaxNGParsePattern(ctxt, child);
if (tmp2 != NULL) { if (tmp2 != NULL) {
if (last2 == NULL) { if (last == NULL) {
except->content = last2 = tmp2; except->content = last = tmp2;
} else { } else {
last2->next = tmp2; last->next = tmp2;
last2 = tmp2; last = tmp2;
} }
} }
child = child->next; child = child->next;
...@@ -7796,8 +7794,6 @@ xmlRelaxNGValidateCompiledCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED, ...@@ -7796,8 +7794,6 @@ xmlRelaxNGValidateCompiledCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED,
#endif #endif
if (ctxt == NULL) { if (ctxt == NULL) {
fprintf(stderr, "callback on %s missing context\n", token); fprintf(stderr, "callback on %s missing context\n", token);
if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
return; return;
} }
if (define == NULL) { if (define == NULL) {
...@@ -7841,10 +7837,11 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt, ...@@ -7841,10 +7837,11 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt,
xmlRegExecCtxtPtr exec; xmlRegExecCtxtPtr exec;
xmlNodePtr cur; xmlNodePtr cur;
int ret = 0; int ret = 0;
int oldperr = ctxt->perr; int oldperr;
if ((ctxt == NULL) || (regexp == NULL)) if ((ctxt == NULL) || (regexp == NULL))
return (-1); return (-1);
oldperr = ctxt->perr;
exec = xmlRegNewExecCtxt(regexp, exec = xmlRegNewExecCtxt(regexp,
xmlRelaxNGValidateCompiledCallback, ctxt); xmlRelaxNGValidateCompiledCallback, ctxt);
ctxt->perr = 0; ctxt->perr = 0;
...@@ -8003,7 +8000,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec ...@@ -8003,7 +8000,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec
xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata; xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
xmlRelaxNGDefinePtr define = (xmlRelaxNGDefinePtr) transdata; xmlRelaxNGDefinePtr define = (xmlRelaxNGDefinePtr) transdata;
xmlRelaxNGValidStatePtr state, oldstate; xmlRelaxNGValidStatePtr state, oldstate;
xmlNodePtr node = ctxt->pnode; xmlNodePtr node;
int ret = 0, oldflags; int ret = 0, oldflags;
#ifdef DEBUG_PROGRESSIVE #ifdef DEBUG_PROGRESSIVE
...@@ -8014,6 +8011,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec ...@@ -8014,6 +8011,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec
fprintf(stderr, "callback on %s missing context\n", token); fprintf(stderr, "callback on %s missing context\n", token);
return; return;
} }
node = ctxt->pnode;
ctxt->pstate = 1; ctxt->pstate = 1;
if (define == NULL) { if (define == NULL) {
if (token[0] == '#') if (token[0] == '#')
...@@ -8767,13 +8765,8 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, ...@@ -8767,13 +8765,8 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
cur = ctxt->state->value; cur = ctxt->state->value;
} }
ctxt->flags = oldflags; ctxt->flags = oldflags;
if (ret != 0) { if (ctxt->errNr > 0)
if ((ctxt->flags & FLAGS_IGNORABLE) == 0) xmlRelaxNGPopErrors(ctxt, 0);
xmlRelaxNGDumpValidError(ctxt);
} else {
if (ctxt->errNr > 0)
xmlRelaxNGPopErrors(ctxt, 0);
}
break; break;
} }
case XML_RELAXNG_EXCEPT:{ case XML_RELAXNG_EXCEPT:{
...@@ -10091,6 +10084,11 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt, ...@@ -10091,6 +10084,11 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
if (states == NULL) { if (states == NULL) {
xmlRelaxNGNewStates(ctxt, xmlRelaxNGNewStates(ctxt,
res->nbState - base); res->nbState - base);
states = ctxt->states;
if (states == NULL) {
progress = 0;
break;
}
} }
states->nbState = 0; states->nbState = 0;
for (i = base; i < res->nbState; i++) for (i = base; i < res->nbState; i++)
......
...@@ -2232,6 +2232,8 @@ xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt, ...@@ -2232,6 +2232,8 @@ xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
{ {
xmlChar *msg = NULL; xmlChar *msg = NULL;
if (actxt == NULL)
return;
msg = xmlStrdup(BAD_CAST "Internal error: "); msg = xmlStrdup(BAD_CAST "Internal error: ");
msg = xmlStrcat(msg, BAD_CAST funcName); msg = xmlStrcat(msg, BAD_CAST funcName);
msg = xmlStrcat(msg, BAD_CAST ", "); msg = xmlStrcat(msg, BAD_CAST ", ");
...@@ -2820,9 +2822,15 @@ xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, ...@@ -2820,9 +2822,15 @@ xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
des = *ownerDes; des = *ownerDes;
} else } else
des = *ownerDes; des = *ownerDes;
xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, if (attr == NULL) {
"%s, attribute '%s': %s.\n", xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
BAD_CAST des, attr->name, (const xmlChar *) msg, 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) if (ownerDes == NULL)
FREE_AND_NULL(des); FREE_AND_NULL(des);
} }
...@@ -7991,7 +7999,10 @@ xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, ...@@ -7991,7 +7999,10 @@ xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt,
* TODO: Call xmlPatterncompile with different options for selector/ * TODO: Call xmlPatterncompile with different options for selector/
* field. * 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. * Build an array of prefixes and namespaces.
*/ */
...@@ -15505,8 +15516,7 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt, ...@@ -15505,8 +15516,7 @@ xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
if (baseMember == NULL) { if (baseMember == NULL) {
PERROR_INT("xmlSchemaCheckCOSSTRestricts", PERROR_INT("xmlSchemaCheckCOSSTRestricts",
"different number of member types in base"); "different number of member types in base");
} } else if ((member->type != baseMember->type) &&
if ((member->type != baseMember->type) &&
(xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
member->type, baseMember->type, 0) != 0)) { member->type, baseMember->type, 0) != 0)) {
xmlChar *strBMT = NULL, *strBT = NULL; xmlChar *strBMT = NULL, *strBT = NULL;
...@@ -24592,7 +24602,7 @@ static int ...@@ -24592,7 +24602,7 @@ static int
xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt) xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
{ {
xmlSchemaElementPtr elemDecl = vctxt->inode->decl; xmlSchemaElementPtr elemDecl = vctxt->inode->decl;
xmlSchemaTypePtr actualType = WXS_ELEM_TYPEDEF(elemDecl); xmlSchemaTypePtr actualType;
/* /*
* cvc-elt (3.3.4) : 1 * cvc-elt (3.3.4) : 1
...@@ -24602,6 +24612,7 @@ xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt) ...@@ -24602,6 +24612,7 @@ xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
"No matching declaration available"); "No matching declaration available");
return (vctxt->err); return (vctxt->err);
} }
actualType = WXS_ELEM_TYPEDEF(elemDecl);
/* /*
* cvc-elt (3.3.4) : 2 * cvc-elt (3.3.4) : 2
*/ */
...@@ -27460,7 +27471,7 @@ xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt) ...@@ -27460,7 +27471,7 @@ xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt)
/* /*
* Process character content. * 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; ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
ret = xmlSchemaVPushText(vctxt, node->type, node->content, ret = xmlSchemaVPushText(vctxt, node->type, node->content,
-1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL); -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL);
...@@ -27991,6 +28002,8 @@ static void ...@@ -27991,6 +28002,8 @@ static void
referenceSplit(void *ctx, const xmlChar *name) referenceSplit(void *ctx, const xmlChar *name)
{ {
xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx; xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
if (ctxt == NULL)
return;
if ((ctxt != NULL) && (ctxt->user_sax != NULL) && if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
(ctxt->user_sax->reference != NULL)) (ctxt->user_sax->reference != NULL))
ctxt->user_sax->reference(ctxt->user_data, name); ctxt->user_sax->reference(ctxt->user_data, name);
......
...@@ -237,6 +237,9 @@ xmlSchemaNewMinLengthFacet(int value) ...@@ -237,6 +237,9 @@ xmlSchemaNewMinLengthFacet(int value)
xmlSchemaFacetPtr ret; xmlSchemaFacetPtr ret;
ret = xmlSchemaNewFacet(); ret = xmlSchemaNewFacet();
if (ret == NULL) {
return(NULL);
}
ret->type = XML_SCHEMA_FACET_MINLENGTH; ret->type = XML_SCHEMA_FACET_MINLENGTH;
ret->val = xmlSchemaNewValue(XML_SCHEMAS_NNINTEGER); ret->val = xmlSchemaNewValue(XML_SCHEMAS_NNINTEGER);
ret->val->value.decimal.lo = value; ret->val->value.decimal.lo = value;
...@@ -1390,11 +1393,12 @@ _xmlSchemaParseTime (xmlSchemaValDatePtr dt, const xmlChar **str) { ...@@ -1390,11 +1393,12 @@ _xmlSchemaParseTime (xmlSchemaValDatePtr dt, const xmlChar **str) {
*/ */
static int static int
_xmlSchemaParseTimeZone (xmlSchemaValDatePtr dt, const xmlChar **str) { _xmlSchemaParseTimeZone (xmlSchemaValDatePtr dt, const xmlChar **str) {
const xmlChar *cur = *str; const xmlChar *cur;
int ret = 0; int ret = 0;
if (str == NULL) if (str == NULL)
return -1; return -1;
cur = *str;
switch (*cur) { switch (*cur) {
case 0: case 0:
...@@ -2386,9 +2390,6 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value, ...@@ -2386,9 +2390,6 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
const xmlChar *cur = value; const xmlChar *cur = value;
int neg = 0; int neg = 0;
if (cur == NULL)
goto return1;
if (normOnTheFly) if (normOnTheFly)
while IS_WSP_BLANK_CH(*cur) cur++; while IS_WSP_BLANK_CH(*cur) cur++;
...@@ -3818,6 +3819,14 @@ _xmlSchemaDateAdd (xmlSchemaValPtr dt, xmlSchemaValPtr dur) ...@@ -3818,6 +3819,14 @@ _xmlSchemaDateAdd (xmlSchemaValPtr dt, xmlSchemaValPtr dur)
long tyr = r->year + (long)FQUOTIENT_RANGE((int)r->mon-1, 1, 13); long tyr = r->year + (long)FQUOTIENT_RANGE((int)r->mon-1, 1, 13);
if (tyr == 0) if (tyr == 0)
tyr--; 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); tempdays += MAX_DAYINMONTH(tyr, tmon);
carry = -1; carry = -1;
} else if (tempdays > (long) MAX_DAYINMONTH(r->year, r->mon)) { } else if (tempdays > (long) MAX_DAYINMONTH(r->year, r->mon)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment