summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2023-03-12 19:07:23 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2023-03-12 19:07:23 +0100
commitcabde70f8b144c416a7aef74971dcb4882a697cd (patch)
tree57ff1423908fc218c88c336439ac8e7d07774ca2
parentb75976e02999c453ae80bb1ade72f704a78b95ce (diff)
downloadlibxml2-cabde70f8b144c416a7aef74971dcb4882a697cd.tar.gz
parser: Simplify calculation of available buffer space
-rw-r--r--HTMLparser.c30
-rw-r--r--parser.c29
2 files changed, 10 insertions, 49 deletions
diff --git a/HTMLparser.c b/HTMLparser.c
index ae84e59b..a4e691f0 100644
--- a/HTMLparser.c
+++ b/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];
diff --git a/parser.c b/parser.c
index 556c8366..44331d11 100644
--- a/parser.c
+++ b/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) {