mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-09 04:58:16 +03:00
Remove hacky heuristic from b2dc5675e94aa6b5557ba63f7d66b0f08dd17e4d
Checking whether the context is close to the parent context by hardcoding 250 is not portable (I noticed tests were failing on Morello since the value is 288 there due to pointers being 128 bits). Instead we should ensure that the XML_VCTXT_USE_PCTXT flag is not set in cases where the user data is not actually a parser context (or ideally add a separate field but that would be an ABI break. From what I can see in the source, the XML_VCTXT_USE_PCTXT is only set if the userData field points to a valid context, and if this is not the case the flag should be cleared when changing userData rather than relying on the offset between the two. Looking at the history, I think d7cb33cf44aa688f24215c9cd398c1a26f0d25ff fixed most of the need for this workaround, but it looks like there are a few more locations that need updating; This commit changes two more places to set/clear/copy the XML_VCTXT_USE_PCTXT flag, so this heuristic should not be needed anymore. I've also drop two = NULL assignment in xmllint since this is not needed after a call to memset(). There was also an uninitialized vctxt.flags (and other fields) in `xmlShellValidate()`, which I've fixed by adding a memset() call.
This commit is contained in:
parent
c715ded086
commit
4b959ee168
@ -6769,6 +6769,7 @@ htmlCtxtReset(htmlParserCtxtPtr ctxt)
|
||||
ctxt->disableSAX = 0;
|
||||
ctxt->valid = 1;
|
||||
ctxt->vctxt.userData = ctxt;
|
||||
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
|
||||
ctxt->vctxt.error = xmlParserValidityError;
|
||||
ctxt->vctxt.warning = xmlParserValidityWarning;
|
||||
ctxt->record_info = 0;
|
||||
|
@ -2635,7 +2635,7 @@ xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd,
|
||||
int res = -1;
|
||||
|
||||
if ((ctxt == NULL) || (ctxt->doc == NULL)) return(-1);
|
||||
vctxt.userData = NULL;
|
||||
memset(&vctxt, 0, sizeof(vctxt));
|
||||
vctxt.error = xmlGenericError;
|
||||
vctxt.warning = xmlGenericError;
|
||||
|
||||
|
1
parser.c
1
parser.c
@ -12907,6 +12907,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
|
||||
ctxt->vctxt.error = oldctxt->vctxt.error;
|
||||
ctxt->vctxt.warning = oldctxt->vctxt.warning;
|
||||
ctxt->vctxt.userData = oldctxt->vctxt.userData;
|
||||
ctxt->vctxt.flags = oldctxt->vctxt.flags;
|
||||
}
|
||||
ctxt->external = oldctxt->external;
|
||||
if (ctxt->dict) xmlDictFree(ctxt->dict);
|
||||
|
20
valid.c
20
valid.c
@ -67,9 +67,7 @@ xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra)
|
||||
/* Look up flag to detect if it is part of a parsing
|
||||
context */
|
||||
if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
|
||||
long delta = (char *) ctxt - (char *) ctxt->userData;
|
||||
if ((delta > 0) && (delta < 250))
|
||||
pctxt = ctxt->userData;
|
||||
pctxt = ctxt->userData;
|
||||
}
|
||||
}
|
||||
if (extra)
|
||||
@ -106,9 +104,7 @@ xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error,
|
||||
/* Look up flag to detect if it is part of a parsing
|
||||
context */
|
||||
if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
|
||||
long delta = (char *) ctxt - (char *) ctxt->userData;
|
||||
if ((delta > 0) && (delta < 250))
|
||||
pctxt = ctxt->userData;
|
||||
pctxt = ctxt->userData;
|
||||
}
|
||||
}
|
||||
if (extra)
|
||||
@ -152,9 +148,7 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt,
|
||||
/* Look up flag to detect if it is part of a parsing
|
||||
context */
|
||||
if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
|
||||
long delta = (char *) ctxt - (char *) ctxt->userData;
|
||||
if ((delta > 0) && (delta < 250))
|
||||
pctxt = ctxt->userData;
|
||||
pctxt = ctxt->userData;
|
||||
}
|
||||
}
|
||||
__xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
|
||||
@ -194,9 +188,7 @@ xmlErrValidNodeNr(xmlValidCtxtPtr ctxt,
|
||||
/* Look up flag to detect if it is part of a parsing
|
||||
context */
|
||||
if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
|
||||
long delta = (char *) ctxt - (char *) ctxt->userData;
|
||||
if ((delta > 0) && (delta < 250))
|
||||
pctxt = ctxt->userData;
|
||||
pctxt = ctxt->userData;
|
||||
}
|
||||
}
|
||||
__xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
|
||||
@ -234,9 +226,7 @@ xmlErrValidWarning(xmlValidCtxtPtr ctxt,
|
||||
/* Look up flag to detect if it is part of a parsing
|
||||
context */
|
||||
if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
|
||||
long delta = (char *) ctxt - (char *) ctxt->userData;
|
||||
if ((delta > 0) && (delta < 250))
|
||||
pctxt = ctxt->userData;
|
||||
pctxt = ctxt->userData;
|
||||
}
|
||||
}
|
||||
__xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
|
||||
|
@ -2711,7 +2711,6 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
||||
xmlFreeDtd(dtd);
|
||||
return;
|
||||
}
|
||||
cvp->userData = NULL;
|
||||
cvp->error = xmlGenericError;
|
||||
cvp->warning = xmlGenericError;
|
||||
|
||||
@ -2749,7 +2748,6 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
|
||||
if ((timing) && (!repeat)) {
|
||||
startTimer();
|
||||
}
|
||||
cvp->userData = NULL;
|
||||
cvp->error = xmlGenericError;
|
||||
cvp->warning = xmlGenericError;
|
||||
if (!xmlValidateDocument(cvp, doc)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user