mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-27 18:50:07 +03:00
parser: Simplify calculation of available buffer space
This commit is contained in:
parent
b75976e029
commit
cabde70f8b
30
HTMLparser.c
30
HTMLparser.c
@ -5580,11 +5580,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
||||
|
||||
in = ctxt->input;
|
||||
if (in == NULL) break;
|
||||
if (in->buf == NULL)
|
||||
avail = in->length - (in->cur - in->base);
|
||||
else
|
||||
avail = (ptrdiff_t)xmlBufUse(in->buf->buffer) -
|
||||
(in->cur - in->base);
|
||||
avail = in->end - in->cur;
|
||||
if ((avail == 0) && (terminate)) {
|
||||
htmlAutoCloseOnEnd(ctxt);
|
||||
if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
|
||||
@ -5623,11 +5619,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
||||
cur = in->cur[0];
|
||||
if (IS_BLANK_CH(cur)) {
|
||||
SKIP_BLANKS;
|
||||
if (in->buf == NULL)
|
||||
avail = in->length - (in->cur - in->base);
|
||||
else
|
||||
avail = (ptrdiff_t)xmlBufUse(in->buf->buffer) -
|
||||
(in->cur - in->base);
|
||||
avail = in->end - in->cur;
|
||||
}
|
||||
if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
|
||||
ctxt->sax->setDocumentLocator(ctxt->userData,
|
||||
@ -5666,11 +5658,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
||||
break;
|
||||
case XML_PARSER_MISC:
|
||||
SKIP_BLANKS;
|
||||
if (in->buf == NULL)
|
||||
avail = in->length - (in->cur - in->base);
|
||||
else
|
||||
avail = (ptrdiff_t)xmlBufUse(in->buf->buffer) -
|
||||
(in->cur - in->base);
|
||||
avail = in->end - in->cur;
|
||||
/*
|
||||
* no chars in buffer
|
||||
*/
|
||||
@ -5739,11 +5727,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
||||
break;
|
||||
case XML_PARSER_PROLOG:
|
||||
SKIP_BLANKS;
|
||||
if (in->buf == NULL)
|
||||
avail = in->length - (in->cur - in->base);
|
||||
else
|
||||
avail = (ptrdiff_t)xmlBufUse(in->buf->buffer) -
|
||||
(in->cur - in->base);
|
||||
avail = in->end - in->cur;
|
||||
if (avail < 2)
|
||||
goto done;
|
||||
cur = in->cur[0];
|
||||
@ -5780,11 +5764,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
||||
}
|
||||
break;
|
||||
case XML_PARSER_EPILOG:
|
||||
if (in->buf == NULL)
|
||||
avail = in->length - (in->cur - in->base);
|
||||
else
|
||||
avail = (ptrdiff_t)xmlBufUse(in->buf->buffer) -
|
||||
(in->cur - in->base);
|
||||
avail = in->end - in->cur;
|
||||
if (avail < 1)
|
||||
goto done;
|
||||
cur = in->cur[0];
|
||||
|
29
parser.c
29
parser.c
@ -11492,10 +11492,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
return(0);
|
||||
|
||||
if (ctxt->input == NULL) break;
|
||||
if (ctxt->input->buf == NULL)
|
||||
avail = ctxt->input->length -
|
||||
(ctxt->input->cur - ctxt->input->base);
|
||||
else {
|
||||
if (ctxt->input->buf != NULL) {
|
||||
/*
|
||||
* If we are operating on converted input, try to flush
|
||||
* remaining chars to avoid them stalling in the non-converted
|
||||
@ -11514,9 +11511,8 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
|
||||
base, current);
|
||||
}
|
||||
avail = xmlBufUse(ctxt->input->buf->buffer) -
|
||||
(ctxt->input->cur - ctxt->input->base);
|
||||
}
|
||||
avail = ctxt->input->end - ctxt->input->cur;
|
||||
if (avail < 1)
|
||||
goto done;
|
||||
switch (ctxt->instate) {
|
||||
@ -11925,12 +11921,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
case XML_PARSER_PROLOG:
|
||||
case XML_PARSER_EPILOG:
|
||||
SKIP_BLANKS;
|
||||
if (ctxt->input->buf == NULL)
|
||||
avail = ctxt->input->length -
|
||||
(ctxt->input->cur - ctxt->input->base);
|
||||
else
|
||||
avail = xmlBufUse(ctxt->input->buf->buffer) -
|
||||
(ctxt->input->cur - ctxt->input->base);
|
||||
avail = ctxt->input->end - ctxt->input->cur;
|
||||
if (avail < 2)
|
||||
goto done;
|
||||
cur = ctxt->input->cur[0];
|
||||
@ -12293,22 +12284,12 @@ xmldecl_done:
|
||||
/*
|
||||
* Check for termination
|
||||
*/
|
||||
int cur_avail = 0;
|
||||
|
||||
if (ctxt->input != NULL) {
|
||||
if (ctxt->input->buf == NULL)
|
||||
cur_avail = ctxt->input->length -
|
||||
(ctxt->input->cur - ctxt->input->base);
|
||||
else
|
||||
cur_avail = xmlBufUse(ctxt->input->buf->buffer) -
|
||||
(ctxt->input->cur - ctxt->input->base);
|
||||
}
|
||||
|
||||
if ((ctxt->instate != XML_PARSER_EOF) &&
|
||||
(ctxt->instate != XML_PARSER_EPILOG)) {
|
||||
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
|
||||
}
|
||||
if ((ctxt->instate == XML_PARSER_EPILOG) && (cur_avail > 0)) {
|
||||
if ((ctxt->instate == XML_PARSER_EPILOG) &&
|
||||
(ctxt->input->cur < ctxt->input->end)) {
|
||||
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
|
||||
}
|
||||
if (ctxt->instate != XML_PARSER_EOF) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user