mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
parser: Merge xmlParserInputGrow into xmlGROW
Simplifies the code and makes error handling easier.
This commit is contained in:
53
parser.c
53
parser.c
@@ -2083,38 +2083,45 @@ static void xmlSHRINK (xmlParserCtxtPtr ctxt) {
|
|||||||
xmlGROW (ctxt);
|
xmlGROW (ctxt);
|
||||||
|
|
||||||
static void xmlGROW (xmlParserCtxtPtr ctxt) {
|
static void xmlGROW (xmlParserCtxtPtr ctxt) {
|
||||||
ptrdiff_t curEnd = ctxt->input->end - ctxt->input->cur;
|
xmlParserInputPtr in = ctxt->input;
|
||||||
ptrdiff_t curBase = ctxt->input->cur - ctxt->input->base;
|
xmlParserInputBufferPtr buf = in->buf;
|
||||||
|
ptrdiff_t curEnd = in->end - in->cur;
|
||||||
|
ptrdiff_t curBase = in->cur - in->base;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (buf == NULL)
|
||||||
|
return;
|
||||||
|
/* Don't grow memory buffers. */
|
||||||
|
if ((buf->encoder == NULL) && (buf->readcallback == NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
if (((curEnd > XML_MAX_LOOKUP_LIMIT) ||
|
if (((curEnd > XML_MAX_LOOKUP_LIMIT) ||
|
||||||
(curBase > XML_MAX_LOOKUP_LIMIT)) &&
|
(curBase > XML_MAX_LOOKUP_LIMIT)) &&
|
||||||
((ctxt->input->buf) &&
|
|
||||||
(ctxt->input->buf->readcallback != NULL)) &&
|
|
||||||
((ctxt->options & XML_PARSE_HUGE) == 0)) {
|
((ctxt->options & XML_PARSE_HUGE) == 0)) {
|
||||||
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
|
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
|
||||||
xmlHaltParser(ctxt);
|
xmlHaltParser(ctxt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* TODO: xmlParserInputGrow should take a ctxt argument. */
|
|
||||||
if (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) < 0) {
|
if (xmlBufUse(buf->buffer) > (unsigned int) curBase + INPUT_CHUNK)
|
||||||
/* Could be a memory or IO error. */
|
return;
|
||||||
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "growing buffer");
|
|
||||||
xmlHaltParser(ctxt);
|
ret = xmlParserInputBufferGrow(buf, INPUT_CHUNK);
|
||||||
return;
|
|
||||||
}
|
in->base = xmlBufContent(buf->buffer);
|
||||||
if ((ctxt->input->cur > ctxt->input->end) ||
|
if (in->base == NULL) {
|
||||||
(ctxt->input->cur < ctxt->input->base)) {
|
xmlErrMemory(ctxt, NULL);
|
||||||
xmlHaltParser(ctxt);
|
in->base = BAD_CAST "";
|
||||||
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "cur index out of bound");
|
in->cur = in->base;
|
||||||
return;
|
in->end = in->base;
|
||||||
}
|
return;
|
||||||
if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0)) {
|
|
||||||
if (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) < 0) {
|
|
||||||
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "growing buffer");
|
|
||||||
xmlHaltParser(ctxt);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
in->cur = in->base + curBase;
|
||||||
|
in->end = xmlBufEnd(buf->buffer);
|
||||||
|
|
||||||
|
/* TODO: Get error code from xmlParserInputBufferGrow */
|
||||||
|
if (ret < 0)
|
||||||
|
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Growing input buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SKIP_BLANKS xmlSkipBlankChars(ctxt)
|
#define SKIP_BLANKS xmlSkipBlankChars(ctxt)
|
||||||
|
|||||||
Reference in New Issue
Block a user