mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
parser: Improve error handling
Introduce xmlCtxtSetErrorHandler allowing to set a structured error for a parser context. There already was the "serror" SAX handler but this always receives the parser context as argument. Start to use xmlRaiseMemoryError. Remove useless arguments from memory error functions. Rename xmlErrMemory to xmlCtxtErrMemory. Remove a few calls to xmlGenericError. Remove support for runtime entity debugging.
This commit is contained in:
60
HTMLparser.c
60
HTMLparser.c
@@ -58,9 +58,9 @@ static void htmlParseComment(htmlParserCtxtPtr ctxt);
|
||||
* Handle a redefinition of attribute error
|
||||
*/
|
||||
static void
|
||||
htmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
|
||||
htmlErrMemory(xmlParserCtxtPtr ctxt)
|
||||
{
|
||||
xmlErrMemory(ctxt, extra);
|
||||
xmlCtxtErrMemory(ctxt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value)
|
||||
tmp = xmlRealloc((xmlChar **) ctxt->nameTab,
|
||||
newSize * sizeof(ctxt->nameTab[0]));
|
||||
if (tmp == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return (-1);
|
||||
}
|
||||
ctxt->nameTab = tmp;
|
||||
@@ -185,7 +185,7 @@ htmlNodeInfoPush(htmlParserCtxtPtr ctxt, htmlParserNodeInfo *value)
|
||||
ctxt->nodeInfoMax *
|
||||
sizeof(ctxt->nodeInfoTab[0]));
|
||||
if (ctxt->nodeInfoTab == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
@@ -343,7 +343,7 @@ htmlFindEncoding(xmlParserCtxtPtr ctxt) {
|
||||
return(NULL);
|
||||
ret = xmlStrndup(start, cur - start);
|
||||
if (ret == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@@ -1996,7 +1996,7 @@ static const htmlEntityDesc html40EntitiesTable[] = {
|
||||
buffer##_size *= 2; \
|
||||
tmp = (xmlChar *) xmlRealloc(buffer, buffer##_size); \
|
||||
if (tmp == NULL) { \
|
||||
htmlErrMemory(ctxt, "growing buffer\n"); \
|
||||
htmlErrMemory(ctxt); \
|
||||
xmlFree(buffer); \
|
||||
return(NULL); \
|
||||
} \
|
||||
@@ -2273,7 +2273,7 @@ htmlNewInputStream(htmlParserCtxtPtr ctxt) {
|
||||
|
||||
input = (xmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput));
|
||||
if (input == NULL) {
|
||||
htmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
|
||||
htmlErrMemory(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
memset(input, 0, sizeof(htmlParserInput));
|
||||
@@ -2518,7 +2518,7 @@ htmlParseHTMLName(htmlParserCtxtPtr ctxt) {
|
||||
|
||||
ret = xmlDictLookup(ctxt->dict, loc, i);
|
||||
if (ret == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
@@ -2554,7 +2554,7 @@ htmlParseHTMLName_nonInvasive(htmlParserCtxtPtr ctxt) {
|
||||
|
||||
ret = xmlDictLookup(ctxt->dict, loc, i);
|
||||
if (ret == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
@@ -2599,7 +2599,7 @@ htmlParseName(htmlParserCtxtPtr ctxt) {
|
||||
count = in - ctxt->input->cur;
|
||||
ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
|
||||
if (ret == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
ctxt->input->cur = in;
|
||||
ctxt->input->col += count;
|
||||
return(ret);
|
||||
@@ -2659,7 +2659,7 @@ htmlParseNameComplex(xmlParserCtxtPtr ctxt) {
|
||||
|
||||
ret = xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len);
|
||||
if (ret == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
@@ -2694,7 +2694,7 @@ htmlParseHTMLAttribute(htmlParserCtxtPtr ctxt, const xmlChar stop) {
|
||||
buffer_size = HTML_PARSER_BUFFER_SIZE;
|
||||
buffer = (xmlChar *) xmlMallocAtomic(buffer_size);
|
||||
if (buffer == NULL) {
|
||||
htmlErrMemory(ctxt, "buffer allocation failed\n");
|
||||
htmlErrMemory(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
out = buffer;
|
||||
@@ -2959,7 +2959,7 @@ htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {
|
||||
if (err == 0) {
|
||||
ret = xmlStrndup((BASE_PTR+startPosition), len);
|
||||
if (ret == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
@@ -3020,7 +3020,7 @@ htmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {
|
||||
if (err == 0) {
|
||||
ret = xmlStrndup((BASE_PTR + startPosition), len);
|
||||
if (ret == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
@@ -3330,7 +3330,7 @@ htmlParsePI(htmlParserCtxtPtr ctxt) {
|
||||
}
|
||||
buf = (xmlChar *) xmlMallocAtomic(size);
|
||||
if (buf == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return;
|
||||
}
|
||||
cur = CUR;
|
||||
@@ -3347,7 +3347,7 @@ htmlParsePI(htmlParserCtxtPtr ctxt) {
|
||||
size *= 2;
|
||||
tmp = (xmlChar *) xmlRealloc(buf, size);
|
||||
if (tmp == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
xmlFree(buf);
|
||||
return;
|
||||
}
|
||||
@@ -3428,7 +3428,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
|
||||
SKIP(4);
|
||||
buf = (xmlChar *) xmlMallocAtomic(size);
|
||||
if (buf == NULL) {
|
||||
htmlErrMemory(ctxt, "buffer allocation failed\n");
|
||||
htmlErrMemory(ctxt);
|
||||
return;
|
||||
}
|
||||
len = 0;
|
||||
@@ -3472,7 +3472,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
|
||||
tmp = (xmlChar *) xmlRealloc(buf, size);
|
||||
if (tmp == NULL) {
|
||||
xmlFree(buf);
|
||||
htmlErrMemory(ctxt, "growing buffer failed\n");
|
||||
htmlErrMemory(ctxt);
|
||||
return;
|
||||
}
|
||||
buf = tmp;
|
||||
@@ -3746,7 +3746,7 @@ htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) {
|
||||
encoding ++;
|
||||
copy = xmlStrdup(encoding);
|
||||
if (copy == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
xmlSetDeclaredEncoding(ctxt, copy);
|
||||
}
|
||||
}
|
||||
@@ -3781,7 +3781,7 @@ htmlCheckMeta(htmlParserCtxtPtr ctxt, const xmlChar **atts) {
|
||||
|
||||
copy = xmlStrdup(value);
|
||||
if (copy == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
xmlSetDeclaredEncoding(ctxt, copy);
|
||||
} else if (!xmlStrcasecmp(att, BAD_CAST "content")) {
|
||||
content = value;
|
||||
@@ -3926,7 +3926,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
|
||||
atts = (const xmlChar **)
|
||||
xmlMalloc(maxatts * sizeof(xmlChar *));
|
||||
if (atts == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
if (attvalue != NULL)
|
||||
xmlFree(attvalue);
|
||||
goto failed;
|
||||
@@ -3940,7 +3940,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
|
||||
n = (const xmlChar **) xmlRealloc((void *) atts,
|
||||
maxatts * sizeof(const xmlChar *));
|
||||
if (n == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
if (attvalue != NULL)
|
||||
xmlFree(attvalue);
|
||||
goto failed;
|
||||
@@ -4591,7 +4591,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
|
||||
} else {
|
||||
currentNode = xmlStrdup(ctxt->name);
|
||||
if (currentNode == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -4613,7 +4613,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
|
||||
} else {
|
||||
currentNode = xmlStrdup(ctxt->name);
|
||||
if (currentNode == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -4642,7 +4642,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
|
||||
} else {
|
||||
currentNode = xmlStrdup(ctxt->name);
|
||||
if (currentNode == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -4673,7 +4673,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
|
||||
} else {
|
||||
currentNode = xmlStrdup(ctxt->name);
|
||||
if (currentNode == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -4732,7 +4732,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
|
||||
} else {
|
||||
currentNode = xmlStrdup(ctxt->name);
|
||||
if (currentNode == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -4901,7 +4901,7 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
|
||||
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
|
||||
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
|
||||
if (ctxt->myDoc->intSubset == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
}
|
||||
}
|
||||
if (! ctxt->wellFormed) return(-1);
|
||||
@@ -5786,7 +5786,7 @@ done:
|
||||
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
|
||||
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
|
||||
if (ctxt->myDoc->intSubset == NULL)
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
}
|
||||
}
|
||||
return(ret);
|
||||
@@ -6722,7 +6722,7 @@ htmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size,
|
||||
input = xmlParserInputBufferCreateStatic(buffer, size,
|
||||
XML_CHAR_ENCODING_NONE);
|
||||
if (input == NULL) {
|
||||
htmlErrMemory(ctxt, NULL);
|
||||
htmlErrMemory(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user