mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
encoding: Move rawconsumed accounting to xmlCharEncInput
This commit is contained in:
@@ -2159,6 +2159,11 @@ xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
|
||||
xmlBufShrink(in, c_in);
|
||||
xmlBufAddLen(out, c_out);
|
||||
|
||||
if (input->rawconsumed > ULONG_MAX - (unsigned long)c_in)
|
||||
input->rawconsumed = ULONG_MAX;
|
||||
else
|
||||
input->rawconsumed += c_in;
|
||||
|
||||
if ((c_out == 0) && (ret != 0)) {
|
||||
if (input->error == 0)
|
||||
input->error = xmlEncConvertError(ret);
|
||||
|
||||
@@ -1414,7 +1414,7 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
|
||||
* Is there already some content down the pipe to convert ?
|
||||
*/
|
||||
if (xmlBufIsEmpty(in->buffer) == 0) {
|
||||
size_t processed, use, consumed;
|
||||
size_t processed;
|
||||
|
||||
/*
|
||||
* Shrink the current input buffer.
|
||||
@@ -1426,7 +1426,6 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
|
||||
in->raw = in->buffer;
|
||||
in->buffer = xmlBufCreate();
|
||||
in->rawconsumed = processed;
|
||||
use = xmlBufUse(in->raw);
|
||||
|
||||
/*
|
||||
* TODO: We must flush and decode the whole buffer to make functions
|
||||
@@ -1448,12 +1447,6 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
|
||||
xmlHaltParser(ctxt);
|
||||
return (-1);
|
||||
}
|
||||
consumed = use - xmlBufUse(in->raw);
|
||||
if ((consumed > ULONG_MAX) ||
|
||||
(in->rawconsumed > ULONG_MAX - (unsigned long)consumed))
|
||||
in->rawconsumed = ULONG_MAX;
|
||||
else
|
||||
in->rawconsumed += consumed;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
21
xmlIO.c
21
xmlIO.c
@@ -3111,8 +3111,6 @@ xmlParserInputBufferPush(xmlParserInputBufferPtr in,
|
||||
if (len < 0) return(0);
|
||||
if ((in == NULL) || (in->error)) return(-1);
|
||||
if (in->encoder != NULL) {
|
||||
size_t use, consumed;
|
||||
|
||||
/*
|
||||
* Store the data in the incoming raw buffer
|
||||
*/
|
||||
@@ -3132,16 +3130,9 @@ xmlParserInputBufferPush(xmlParserInputBufferPtr in,
|
||||
/*
|
||||
* convert as much as possible to the parser reading buffer.
|
||||
*/
|
||||
use = xmlBufUse(in->raw);
|
||||
nbchars = xmlCharEncInput(in, 1);
|
||||
if (nbchars < 0)
|
||||
return(-1);
|
||||
consumed = use - xmlBufUse(in->raw);
|
||||
if ((consumed > ULONG_MAX) ||
|
||||
(in->rawconsumed > ULONG_MAX - (unsigned long)consumed))
|
||||
in->rawconsumed = ULONG_MAX;
|
||||
else
|
||||
in->rawconsumed += consumed;
|
||||
} else {
|
||||
nbchars = len;
|
||||
ret = xmlBufAdd(in->buffer, (xmlChar *) buf, nbchars);
|
||||
@@ -3240,21 +3231,9 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
|
||||
}
|
||||
|
||||
if (in->encoder != NULL) {
|
||||
size_t use, consumed;
|
||||
|
||||
/*
|
||||
* convert as much as possible to the parser reading buffer.
|
||||
*/
|
||||
use = xmlBufUse(buf);
|
||||
res = xmlCharEncInput(in, 1);
|
||||
if (res < 0)
|
||||
return(-1);
|
||||
consumed = use - xmlBufUse(buf);
|
||||
if ((consumed > ULONG_MAX) ||
|
||||
(in->rawconsumed > ULONG_MAX - (unsigned long)consumed))
|
||||
in->rawconsumed = ULONG_MAX;
|
||||
else
|
||||
in->rawconsumed += consumed;
|
||||
}
|
||||
#ifdef DEBUG_INPUT
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
|
||||
Reference in New Issue
Block a user