Fix backtracing bug with mpc_parse_pipe

Before we free our buffer we need to reset the underlying stream to its
original state by pushing the buffer contents back onto the input
stream.

Fixes #109
This commit is contained in:
Sören Tempel
2019-06-04 19:50:23 +02:00
parent dbe7308b9c
commit 6f5e8f0f39

4
mpc.c
View File

@@ -320,6 +320,7 @@ static void mpc_input_mark(mpc_input_t *i) {
}
static void mpc_input_unmark(mpc_input_t *i) {
int j;
if (i->backtrack < 1) { return; }
@@ -335,6 +336,9 @@ static void mpc_input_unmark(mpc_input_t *i) {
}
if (i->type == MPC_INPUT_PIPE && i->marks_num == 0) {
for (j = strlen(i->buffer) - 1; j >= 0; j--)
ungetc(i->buffer[j], i->file);
free(i->buffer);
i->buffer = NULL;
}