don't modify input string in XML parser
The XML parser has two modes: it can parse a file or parse a caller-owned string. In the former case, it owns its buffer and shifts the contents to make room for more data read in from the file. This shifting may not happen when parsing a string. Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
62ccd9f7da
commit
b8e4b2a49b
1 changed files with 15 additions and 15 deletions
|
@ -179,22 +179,22 @@ static int make_chars_available (struct ddsrt_xmlp_state *st, size_t nmin)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* ensure buffer space is available */
|
/* ensure buffer space is available */
|
||||||
if (pos + nmin > st->cbufmax) {
|
|
||||||
memmove (st->cbuf, st->cbuf + pos, st->cbufn - pos);
|
|
||||||
st->cbufn -= pos;
|
|
||||||
st->cbufp -= pos;
|
|
||||||
if (st->cbufmark != NOMARKER) {
|
|
||||||
st->cbufmark -= pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* buffer is owned by caller if fp = NULL, and by us if fp != NULL */
|
|
||||||
if (st->cbufp + st->cbufmax < nmin && st->fp != NULL) {
|
|
||||||
st->cbufmax = st->cbufp + nmin;
|
|
||||||
st->cbuf = ddsrt_realloc (st->cbuf, st->cbufmax);
|
|
||||||
}
|
|
||||||
/* try to refill buffer if a backing file is present; eof (or end-of-string) is
|
|
||||||
reached when this doesn't add any bytes to the buffer */
|
|
||||||
if (st->fp != NULL) {
|
if (st->fp != NULL) {
|
||||||
|
if (pos + nmin > st->cbufmax) {
|
||||||
|
memmove (st->cbuf, st->cbuf + pos, st->cbufn - pos);
|
||||||
|
st->cbufn -= pos;
|
||||||
|
st->cbufp -= pos;
|
||||||
|
if (st->cbufmark != NOMARKER) {
|
||||||
|
st->cbufmark -= pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* buffer is owned by caller if fp = NULL, and by us if fp != NULL */
|
||||||
|
if (st->cbufp + st->cbufmax < nmin) {
|
||||||
|
st->cbufmax = st->cbufp + nmin;
|
||||||
|
st->cbuf = ddsrt_realloc (st->cbuf, st->cbufmax);
|
||||||
|
}
|
||||||
|
/* try to refill buffer if a backing file is present; eof (or end-of-string) is
|
||||||
|
reached when this doesn't add any bytes to the buffer */
|
||||||
n = fread (st->cbuf + st->cbufn, 1, st->cbufmax - st->cbufn, st->fp);
|
n = fread (st->cbuf + st->cbufn, 1, st->cbufmax - st->cbufn, st->fp);
|
||||||
st->cbufn += n;
|
st->cbufn += n;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue