diff --git a/error.c b/error.c index fc28bb69..4c7cbc76 100644 --- a/error.c +++ b/error.c @@ -20,6 +20,30 @@ #include "private/globals.h" #include "private/string.h" +int +xmlIsCatastrophicError(int level, int code) { + int fatal = 0; + + if (level != XML_ERR_FATAL) + return(0); + + switch (code) { + case XML_ERR_NO_MEMORY: + /* case XML_ERR_RESOURCE_LIMIT: */ + case XML_ERR_SYSTEM: + case XML_ERR_ARGUMENT: + case XML_ERR_INTERNAL_ERROR: + fatal = 1; + break; + default: + if ((code >= 1500) && (code <= 1599)) + fatal = 1; + break; + } + + return(fatal); +} + /************************************************************************ * * * Error struct * diff --git a/include/private/error.h b/include/private/error.h index d99cfea3..b88fd825 100644 --- a/include/private/error.h +++ b/include/private/error.h @@ -10,6 +10,9 @@ struct _xmlNode; +XML_HIDDEN int +xmlIsCatastrophicError(int level, int code); + XML_HIDDEN void xmlRaiseMemoryError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel, void *data, int domain, xmlError *error); diff --git a/include/private/parser.h b/include/private/parser.h index a0964223..d159c860 100644 --- a/include/private/parser.h +++ b/include/private/parser.h @@ -68,8 +68,6 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, 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 diff --git a/parserInternals.c b/parserInternals.c index e119de4d..12624a6e 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -256,30 +256,6 @@ xmlCtxtErrIO(xmlParserCtxtPtr ctxt, int code, const char *uri) msg, str1, str2); } -int -xmlIsCatastrophicError(int level, int code) { - int fatal = 0; - - if (level != XML_ERR_FATAL) - return(0); - - switch (code) { - case XML_ERR_NO_MEMORY: - /* case XML_ERR_RESOURCE_LIMIT: */ - case XML_ERR_SYSTEM: - case XML_ERR_ARGUMENT: - case XML_ERR_INTERNAL_ERROR: - fatal = 1; - break; - default: - if ((code >= 1500) && (code <= 1599)) - fatal = 1; - break; - } - - return(fatal); -} - int xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt) { if (ctxt == NULL) diff --git a/xmlIO.c b/xmlIO.c index 4e177d43..c490baf9 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -1341,7 +1341,8 @@ xmlOutputBufferClose(xmlOutputBufferPtr out) if (out->closecallback != NULL) { int code = out->closecallback(out->context); - if ((code != XML_ERR_OK) && (out->error == XML_ERR_OK)) { + if ((code != XML_ERR_OK) && + (!xmlIsCatastrophicError(XML_ERR_FATAL, out->error))) { if (code < 0) out->error = XML_IO_UNKNOWN; else diff --git a/xmlsave.c b/xmlsave.c index 6258d05a..d1b97455 100644 --- a/xmlsave.c +++ b/xmlsave.c @@ -83,8 +83,10 @@ xmlSaveErr(xmlOutputBufferPtr out, int code, xmlNodePtr node, const char *msg = NULL; int res; - /* Don't overwrite memory errors */ - if ((out != NULL) && (out->error == XML_ERR_NO_MEMORY)) + /* Don't overwrite catastrophic errors */ + if ((out != NULL) && + (out->error != XML_ERR_OK) && + (xmlIsCatastrophicError(XML_ERR_FATAL, out->error))) return; if (code == XML_ERR_NO_MEMORY) {