Skip to content

Commit 54c70ed

Browse files
committed
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.
1 parent c5a8aef commit 54c70ed

13 files changed

+350
-379
lines changed

HTMLparser.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ static void htmlParseComment(htmlParserCtxtPtr ctxt);
5858
* Handle a redefinition of attribute error
5959
*/
6060
static void
61-
htmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
61+
htmlErrMemory(xmlParserCtxtPtr ctxt)
6262
{
63-
xmlErrMemory(ctxt, extra);
63+
xmlCtxtErrMemory(ctxt);
6464
}
6565

6666
/**
@@ -127,7 +127,7 @@ htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value)
127127
tmp = xmlRealloc((xmlChar **) ctxt->nameTab,
128128
newSize * sizeof(ctxt->nameTab[0]));
129129
if (tmp == NULL) {
130-
htmlErrMemory(ctxt, NULL);
130+
htmlErrMemory(ctxt);
131131
return (-1);
132132
}
133133
ctxt->nameTab = tmp;
@@ -185,7 +185,7 @@ htmlNodeInfoPush(htmlParserCtxtPtr ctxt, htmlParserNodeInfo *value)
185185
ctxt->nodeInfoMax *
186186
sizeof(ctxt->nodeInfoTab[0]));
187187
if (ctxt->nodeInfoTab == NULL) {
188-
htmlErrMemory(ctxt, NULL);
188+
htmlErrMemory(ctxt);
189189
return (0);
190190
}
191191
}
@@ -343,7 +343,7 @@ htmlFindEncoding(xmlParserCtxtPtr ctxt) {
343343
return(NULL);
344344
ret = xmlStrndup(start, cur - start);
345345
if (ret == NULL)
346-
htmlErrMemory(ctxt, NULL);
346+
htmlErrMemory(ctxt);
347347
return(ret);
348348
}
349349

@@ -1996,7 +1996,7 @@ static const htmlEntityDesc html40EntitiesTable[] = {
19961996
buffer##_size *= 2; \
19971997
tmp = (xmlChar *) xmlRealloc(buffer, buffer##_size); \
19981998
if (tmp == NULL) { \
1999-
htmlErrMemory(ctxt, "growing buffer\n"); \
1999+
htmlErrMemory(ctxt); \
20002000
xmlFree(buffer); \
20012001
return(NULL); \
20022002
} \
@@ -2273,7 +2273,7 @@ htmlNewInputStream(htmlParserCtxtPtr ctxt) {
22732273

22742274
input = (xmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput));
22752275
if (input == NULL) {
2276-
htmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
2276+
htmlErrMemory(ctxt);
22772277
return(NULL);
22782278
}
22792279
memset(input, 0, sizeof(htmlParserInput));
@@ -2518,7 +2518,7 @@ htmlParseHTMLName(htmlParserCtxtPtr ctxt) {
25182518

25192519
ret = xmlDictLookup(ctxt->dict, loc, i);
25202520
if (ret == NULL)
2521-
htmlErrMemory(ctxt, NULL);
2521+
htmlErrMemory(ctxt);
25222522

25232523
return(ret);
25242524
}
@@ -2554,7 +2554,7 @@ htmlParseHTMLName_nonInvasive(htmlParserCtxtPtr ctxt) {
25542554

25552555
ret = xmlDictLookup(ctxt->dict, loc, i);
25562556
if (ret == NULL)
2557-
htmlErrMemory(ctxt, NULL);
2557+
htmlErrMemory(ctxt);
25582558

25592559
return(ret);
25602560
}
@@ -2599,7 +2599,7 @@ htmlParseName(htmlParserCtxtPtr ctxt) {
25992599
count = in - ctxt->input->cur;
26002600
ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
26012601
if (ret == NULL)
2602-
htmlErrMemory(ctxt, NULL);
2602+
htmlErrMemory(ctxt);
26032603
ctxt->input->cur = in;
26042604
ctxt->input->col += count;
26052605
return(ret);
@@ -2659,7 +2659,7 @@ htmlParseNameComplex(xmlParserCtxtPtr ctxt) {
26592659

26602660
ret = xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len);
26612661
if (ret == NULL)
2662-
htmlErrMemory(ctxt, NULL);
2662+
htmlErrMemory(ctxt);
26632663

26642664
return(ret);
26652665
}
@@ -2694,7 +2694,7 @@ htmlParseHTMLAttribute(htmlParserCtxtPtr ctxt, const xmlChar stop) {
26942694
buffer_size = HTML_PARSER_BUFFER_SIZE;
26952695
buffer = (xmlChar *) xmlMallocAtomic(buffer_size);
26962696
if (buffer == NULL) {
2697-
htmlErrMemory(ctxt, "buffer allocation failed\n");
2697+
htmlErrMemory(ctxt);
26982698
return(NULL);
26992699
}
27002700
out = buffer;
@@ -2959,7 +2959,7 @@ htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {
29592959
if (err == 0) {
29602960
ret = xmlStrndup((BASE_PTR+startPosition), len);
29612961
if (ret == NULL) {
2962-
htmlErrMemory(ctxt, NULL);
2962+
htmlErrMemory(ctxt);
29632963
return(NULL);
29642964
}
29652965
}
@@ -3020,7 +3020,7 @@ htmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {
30203020
if (err == 0) {
30213021
ret = xmlStrndup((BASE_PTR + startPosition), len);
30223022
if (ret == NULL) {
3023-
htmlErrMemory(ctxt, NULL);
3023+
htmlErrMemory(ctxt);
30243024
return(NULL);
30253025
}
30263026
}
@@ -3330,7 +3330,7 @@ htmlParsePI(htmlParserCtxtPtr ctxt) {
33303330
}
33313331
buf = (xmlChar *) xmlMallocAtomic(size);
33323332
if (buf == NULL) {
3333-
htmlErrMemory(ctxt, NULL);
3333+
htmlErrMemory(ctxt);
33343334
return;
33353335
}
33363336
cur = CUR;
@@ -3347,7 +3347,7 @@ htmlParsePI(htmlParserCtxtPtr ctxt) {
33473347
size *= 2;
33483348
tmp = (xmlChar *) xmlRealloc(buf, size);
33493349
if (tmp == NULL) {
3350-
htmlErrMemory(ctxt, NULL);
3350+
htmlErrMemory(ctxt);
33513351
xmlFree(buf);
33523352
return;
33533353
}
@@ -3428,7 +3428,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
34283428
SKIP(4);
34293429
buf = (xmlChar *) xmlMallocAtomic(size);
34303430
if (buf == NULL) {
3431-
htmlErrMemory(ctxt, "buffer allocation failed\n");
3431+
htmlErrMemory(ctxt);
34323432
return;
34333433
}
34343434
len = 0;
@@ -3472,7 +3472,7 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
34723472
tmp = (xmlChar *) xmlRealloc(buf, size);
34733473
if (tmp == NULL) {
34743474
xmlFree(buf);
3475-
htmlErrMemory(ctxt, "growing buffer failed\n");
3475+
htmlErrMemory(ctxt);
34763476
return;
34773477
}
34783478
buf = tmp;
@@ -3746,7 +3746,7 @@ htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) {
37463746
encoding ++;
37473747
copy = xmlStrdup(encoding);
37483748
if (copy == NULL)
3749-
htmlErrMemory(ctxt, NULL);
3749+
htmlErrMemory(ctxt);
37503750
xmlSetDeclaredEncoding(ctxt, copy);
37513751
}
37523752
}
@@ -3781,7 +3781,7 @@ htmlCheckMeta(htmlParserCtxtPtr ctxt, const xmlChar **atts) {
37813781

37823782
copy = xmlStrdup(value);
37833783
if (copy == NULL)
3784-
htmlErrMemory(ctxt, NULL);
3784+
htmlErrMemory(ctxt);
37853785
xmlSetDeclaredEncoding(ctxt, copy);
37863786
} else if (!xmlStrcasecmp(att, BAD_CAST "content")) {
37873787
content = value;
@@ -3926,7 +3926,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
39263926
atts = (const xmlChar **)
39273927
xmlMalloc(maxatts * sizeof(xmlChar *));
39283928
if (atts == NULL) {
3929-
htmlErrMemory(ctxt, NULL);
3929+
htmlErrMemory(ctxt);
39303930
if (attvalue != NULL)
39313931
xmlFree(attvalue);
39323932
goto failed;
@@ -3940,7 +3940,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
39403940
n = (const xmlChar **) xmlRealloc((void *) atts,
39413941
maxatts * sizeof(const xmlChar *));
39423942
if (n == NULL) {
3943-
htmlErrMemory(ctxt, NULL);
3943+
htmlErrMemory(ctxt);
39443944
if (attvalue != NULL)
39453945
xmlFree(attvalue);
39463946
goto failed;
@@ -4591,7 +4591,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
45914591
} else {
45924592
currentNode = xmlStrdup(ctxt->name);
45934593
if (currentNode == NULL) {
4594-
htmlErrMemory(ctxt, NULL);
4594+
htmlErrMemory(ctxt);
45954595
return;
45964596
}
45974597
}
@@ -4613,7 +4613,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
46134613
} else {
46144614
currentNode = xmlStrdup(ctxt->name);
46154615
if (currentNode == NULL) {
4616-
htmlErrMemory(ctxt, NULL);
4616+
htmlErrMemory(ctxt);
46174617
break;
46184618
}
46194619
}
@@ -4642,7 +4642,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
46424642
} else {
46434643
currentNode = xmlStrdup(ctxt->name);
46444644
if (currentNode == NULL) {
4645-
htmlErrMemory(ctxt, NULL);
4645+
htmlErrMemory(ctxt);
46464646
break;
46474647
}
46484648
}
@@ -4673,7 +4673,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
46734673
} else {
46744674
currentNode = xmlStrdup(ctxt->name);
46754675
if (currentNode == NULL) {
4676-
htmlErrMemory(ctxt, NULL);
4676+
htmlErrMemory(ctxt);
46774677
break;
46784678
}
46794679
}
@@ -4732,7 +4732,7 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
47324732
} else {
47334733
currentNode = xmlStrdup(ctxt->name);
47344734
if (currentNode == NULL) {
4735-
htmlErrMemory(ctxt, NULL);
4735+
htmlErrMemory(ctxt);
47364736
break;
47374737
}
47384738
}
@@ -4901,7 +4901,7 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
49014901
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
49024902
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
49034903
if (ctxt->myDoc->intSubset == NULL)
4904-
htmlErrMemory(ctxt, NULL);
4904+
htmlErrMemory(ctxt);
49054905
}
49064906
}
49074907
if (! ctxt->wellFormed) return(-1);
@@ -5786,7 +5786,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
57865786
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
57875787
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
57885788
if (ctxt->myDoc->intSubset == NULL)
5789-
htmlErrMemory(ctxt, NULL);
5789+
htmlErrMemory(ctxt);
57905790
}
57915791
}
57925792
return(ret);
@@ -6722,7 +6722,7 @@ htmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size,
67226722
input = xmlParserInputBufferCreateStatic(buffer, size,
67236723
XML_CHAR_ENCODING_NONE);
67246724
if (input == NULL) {
6725-
htmlErrMemory(ctxt, NULL);
6725+
htmlErrMemory(ctxt);
67266726
return(NULL);
67276727
}
67286728

0 commit comments

Comments
 (0)