From 6f5e8f0f398e624b51bec54541833b27c1c139ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Tue, 4 Jun 2019 19:50:23 +0200 Subject: [PATCH] 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 --- mpc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mpc.c b/mpc.c index 9856efa..87aac4c 100644 --- a/mpc.c +++ b/mpc.c @@ -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; }