diff --git a/HTMLparser.c b/HTMLparser.c index d0fa178b..a5929c37 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -6042,12 +6042,11 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size, } if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input); - size_t cur = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { htmlParseErr(ctxt, ctxt->input->buf->error, "xmlParserInputBufferPush failed", NULL, NULL); @@ -6068,11 +6067,10 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size, if ((in->encoder != NULL) && (in->buffer != NULL) && (in->raw != NULL)) { int nbchars; - size_t base = xmlBufGetInputBase(in->buffer, ctxt->input); - size_t current = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; nbchars = xmlCharEncInput(in, terminate); - xmlBufSetInputBaseCur(in->buffer, ctxt->input, base, current); + xmlBufUpdateInput(in->buffer, ctxt->input, pos); if (nbchars < 0) { htmlParseErr(ctxt, in->error, "encoder error\n", NULL, NULL); @@ -6163,12 +6161,11 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data, if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input); - size_t cur = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { htmlParseErr(ctxt, ctxt->input->buf->error, "xmlParserInputBufferPush failed\n", NULL, NULL); diff --git a/buf.c b/buf.c index fbaf926a..769ea9a3 100644 --- a/buf.c +++ b/buf.c @@ -1056,39 +1056,10 @@ xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input) { } /** - * xmlBufGetInputBase: + * xmlBufUpdateInput: * @buf: an xmlBufPtr * @input: an xmlParserInputPtr - * - * Get the base of the @input relative to the beginning of the buffer - * - * Returns the size_t corresponding to the displacement - */ -size_t -xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input) { - size_t base; - - if ((input == NULL) || (buf == NULL) || (buf->error)) - return(0); - CHECK_COMPAT(buf) - base = input->base - buf->content; - /* - * We could do some pointer arithmetic checks but that's probably - * sufficient. - */ - if (base > buf->size) { - xmlBufOverflowError(buf, "Input reference outside of the buffer"); - base = 0; - } - return(base); -} - -/** - * xmlBufSetInputBaseCur: - * @buf: an xmlBufPtr - * @input: an xmlParserInputPtr - * @base: the base value relative to the beginning of the buffer - * @cur: the cur value relative to the beginning of the buffer + * @pos: the cur value relative to the beginning of the buffer * * Update the input to use the base and cur relative to the buffer * after a possible reallocation of its content @@ -1096,8 +1067,7 @@ xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input) { * Returns -1 in case of error, 0 otherwise */ int -xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, - size_t base, size_t cur) { +xmlBufUpdateInput(xmlBufPtr buf, xmlParserInputPtr input, size_t pos) { if (input == NULL) return(-1); /* @@ -1109,8 +1079,8 @@ xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, return(-1); } CHECK_COMPAT(buf) - input->base = &buf->content[base]; - input->cur = input->base + cur; + input->base = buf->content; + input->cur = input->base + pos; input->end = &buf->content[buf->use]; return(0); } diff --git a/include/private/buf.h b/include/private/buf.h index c18eed42..6fef4ce0 100644 --- a/include/private/buf.h +++ b/include/private/buf.h @@ -61,10 +61,7 @@ xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer); XML_HIDDEN int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input); -XML_HIDDEN size_t -xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input); XML_HIDDEN int -xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, - size_t base, size_t cur); +xmlBufUpdateInput(xmlBufPtr buf, xmlParserInputPtr input, size_t pos); #endif /* XML_BUF_H_PRIVATE__ */ diff --git a/parser.c b/parser.c index 2770bd94..7eef2869 100644 --- a/parser.c +++ b/parser.c @@ -11007,14 +11007,11 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { */ if ((ctxt->input->buf->raw != NULL) && (xmlBufIsEmpty(ctxt->input->buf->raw) == 0)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, - ctxt->input); - size_t current = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, 0, ""); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, - base, current); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { xmlFatalErr(ctxt, ctxt->input->buf->error, NULL); xmlHaltParser(ctxt); @@ -11669,12 +11666,11 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input); - size_t cur = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { xmlFatalErr(ctxt, ctxt->input->buf->error, NULL); xmlHaltParser(ctxt); @@ -11690,11 +11686,10 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, if ((in->encoder != NULL) && (in->buffer != NULL) && (in->raw != NULL)) { int nbchars; - size_t base = xmlBufGetInputBase(in->buffer, ctxt->input); - size_t current = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; nbchars = xmlCharEncInput(in, terminate); - xmlBufSetInputBaseCur(in->buffer, ctxt->input, base, current); + xmlBufUpdateInput(in->buffer, ctxt->input, pos); if (nbchars < 0) { xmlFatalErr(ctxt, in->error, NULL); xmlHaltParser(ctxt); @@ -11720,14 +11715,11 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, if ((end_in_lf == 1) && (ctxt->input != NULL) && (ctxt->input->buf != NULL)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, - ctxt->input); - size_t current = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, 1, "\r"); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, - base, current); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { xmlFatalErr(ctxt, ctxt->input->buf->error, NULL); xmlHaltParser(ctxt); @@ -11831,12 +11823,11 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, if ((size != 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input); - size_t cur = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { xmlFatalErr(ctxt, ctxt->input->buf->error, NULL); xmlHaltParser(ctxt); @@ -14146,12 +14137,11 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk, if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL)) { - size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input); - size_t cur = ctxt->input->cur - ctxt->input->base; + size_t pos = ctxt->input->cur - ctxt->input->base; int res; res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); - xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur); + xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); if (res < 0) { xmlFatalErr(ctxt, ctxt->input->buf->error, NULL); xmlHaltParser(ctxt); diff --git a/parserInternals.c b/parserInternals.c index d6de79fe..c40e0654 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -564,7 +564,7 @@ xmlParserGrow(xmlParserCtxtPtr ctxt) { return(0); ret = xmlParserInputBufferGrow(buf, INPUT_CHUNK); - xmlBufSetInputBaseCur(buf->buffer, in, 0, curBase); + xmlBufUpdateInput(buf->buffer, in, curBase); if (ret < 0) { xmlFatalErr(ctxt, buf->error, NULL); @@ -667,7 +667,7 @@ xmlParserShrink(xmlParserCtxtPtr ctxt) { } } - xmlBufSetInputBaseCur(buf->buffer, in, 0, used); + xmlBufUpdateInput(buf->buffer, in, used); } /**