diff --git a/include/private/parser.h b/include/private/parser.h index 79a1bf67..a0964223 100644 --- a/include/private/parser.h +++ b/include/private/parser.h @@ -67,6 +67,10 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *msg, const xmlChar *str1, const xmlChar *str2); XML_HIDDEN void xmlCtxtErrIO(xmlParserCtxtPtr ctxt, int code, const char *uri); +XML_HIDDEN int +xmlIsCatastrophicError(int level, int code); +XML_HIDDEN int +xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt); XML_HIDDEN void xmlHaltParser(xmlParserCtxtPtr ctxt); diff --git a/parserInternals.c b/parserInternals.c index b062fbbc..18880c8c 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -254,19 +254,13 @@ xmlCtxtErrIO(xmlParserCtxtPtr ctxt, int code, const char *uri) msg, str1, str2); } -static int -xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt) { +int +xmlIsCatastrophicError(int level, int code) { int fatal = 0; - int code; - if (ctxt == NULL) - return(1); - - if (ctxt->lastError.level != XML_ERR_FATAL) + if (level != XML_ERR_FATAL) return(0); - code = ctxt->lastError.code; - switch (code) { case XML_ERR_NO_MEMORY: case XML_ERR_RESOURCE_LIMIT: @@ -284,6 +278,15 @@ xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt) { return(fatal); } +int +xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt) { + if (ctxt == NULL) + return(1); + + return(xmlIsCatastrophicError(ctxt->lastError.level, + ctxt->lastError.code)); +} + /** * xmlCtxtVErr: * @ctxt: a parser context @@ -325,15 +328,20 @@ xmlCtxtVErr(xmlParserCtxtPtr ctxt, xmlNodePtr node, xmlErrorDomain domain, if (PARSER_STOPPED(ctxt)) return; + /* Don't overwrite catastrophic errors */ + if (xmlCtxtIsCatastrophicError(ctxt)) + return; + if (level == XML_ERR_WARNING) { if (ctxt->nbWarnings >= XML_MAX_ERRORS) - goto done; + return; ctxt->nbWarnings += 1; } else { /* Report at least one fatal error. */ if ((ctxt->nbErrors >= XML_MAX_ERRORS) && - ((level < XML_ERR_FATAL) || (ctxt->wellFormed == 0))) - goto done; + ((level < XML_ERR_FATAL) || (ctxt->wellFormed == 0)) && + (!xmlIsCatastrophicError(level, code))) + return; ctxt->nbErrors += 1; } @@ -384,7 +392,6 @@ xmlCtxtVErr(xmlParserCtxtPtr ctxt, xmlNodePtr node, xmlErrorDomain domain, return; } -done: if (level >= XML_ERR_ERROR) ctxt->errNo = code; if (level == XML_ERR_FATAL) {