mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-28 07:21:26 +03:00
xmlBufAvail() should return length without including a byte for NUL terminator
* buf.c: (xmlBufAvail): - Return the number of bytes available in the buffer, but do not include a byte for the NUL terminator so that it is reserved. * encoding.c: (xmlCharEncFirstLineInput): (xmlCharEncInput): (xmlCharEncOutput): * xmlIO.c: (xmlOutputBufferWriteEscape): - Remove code that subtracts 1 from the return value of xmlBufAvail(). It was implemented inconsistently anyway.
This commit is contained in:
parent
fe9f76ebb8
commit
c14cac8bba
9
buf.c
9
buf.c
@ -645,10 +645,11 @@ xmlBufUse(const xmlBufPtr buf)
|
||||
* @buf: the buffer
|
||||
*
|
||||
* Function to find how much free space is allocated but not
|
||||
* used in the buffer. It does not account for the terminating zero
|
||||
* usually needed
|
||||
* used in the buffer. It reserves one byte for the NUL
|
||||
* terminator character that is usually needed, so there is
|
||||
* no need to subtract 1 from the result anymore.
|
||||
*
|
||||
* Returns the amount or 0 if none or an error occurred
|
||||
* Returns the amount, or 0 if none or if an error occurred.
|
||||
*/
|
||||
|
||||
size_t
|
||||
@ -658,7 +659,7 @@ xmlBufAvail(const xmlBufPtr buf)
|
||||
return 0;
|
||||
CHECK_COMPAT(buf)
|
||||
|
||||
return(buf->size - buf->use);
|
||||
return((buf->size > buf->use) ? (buf->size - buf->use - 1) : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
14
encoding.c
14
encoding.c
@ -2197,7 +2197,7 @@ xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
|
||||
toconv = xmlBufUse(in);
|
||||
if (toconv == 0)
|
||||
return (0);
|
||||
written = xmlBufAvail(out) - 1; /* count '\0' */
|
||||
written = xmlBufAvail(out);
|
||||
/*
|
||||
* echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
|
||||
* 45 chars should be sufficient to reach the end of the encoding
|
||||
@ -2215,7 +2215,7 @@ xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
|
||||
}
|
||||
if (toconv * 2 >= written) {
|
||||
xmlBufGrow(out, toconv * 2);
|
||||
written = xmlBufAvail(out) - 1;
|
||||
written = xmlBufAvail(out);
|
||||
}
|
||||
if (written > 360)
|
||||
written = 360;
|
||||
@ -2307,13 +2307,9 @@ xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
|
||||
if ((toconv > 64 * 1024) && (flush == 0))
|
||||
toconv = 64 * 1024;
|
||||
written = xmlBufAvail(out);
|
||||
if (written > 0)
|
||||
written--; /* count '\0' */
|
||||
if (toconv * 2 >= written) {
|
||||
xmlBufGrow(out, toconv * 2);
|
||||
written = xmlBufAvail(out);
|
||||
if (written > 0)
|
||||
written--; /* count '\0' */
|
||||
}
|
||||
if ((written > 128 * 1024) && (flush == 0))
|
||||
written = 128 * 1024;
|
||||
@ -2495,8 +2491,6 @@ xmlCharEncOutput(xmlOutputBufferPtr output, int init)
|
||||
retry:
|
||||
|
||||
written = xmlBufAvail(out);
|
||||
if (written > 0)
|
||||
written--; /* count '\0' */
|
||||
|
||||
/*
|
||||
* First specific handling of the initialization call
|
||||
@ -2525,7 +2519,7 @@ retry:
|
||||
toconv = 64 * 1024;
|
||||
if (toconv * 4 >= written) {
|
||||
xmlBufGrow(out, toconv * 4);
|
||||
written = xmlBufAvail(out) - 1;
|
||||
written = xmlBufAvail(out);
|
||||
}
|
||||
if (written > 256 * 1024)
|
||||
written = 256 * 1024;
|
||||
@ -2600,7 +2594,7 @@ retry:
|
||||
"&#%d;", cur);
|
||||
xmlBufShrink(in, len);
|
||||
xmlBufGrow(out, charrefLen * 4);
|
||||
c_out = xmlBufAvail(out) - 1;
|
||||
c_out = xmlBufAvail(out);
|
||||
c_in = charrefLen;
|
||||
ret = xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
|
||||
charref, &c_in);
|
||||
|
2
xmlIO.c
2
xmlIO.c
@ -3547,7 +3547,7 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str,
|
||||
* how many bytes to consume and how many bytes to store.
|
||||
*/
|
||||
cons = len;
|
||||
chunk = xmlBufAvail(out->buffer) - 1;
|
||||
chunk = xmlBufAvail(out->buffer);
|
||||
|
||||
/*
|
||||
* make sure we have enough room to save first, if this is
|
||||
|
Loading…
Reference in New Issue
Block a user