From 8a8ad233125ff42cb4b31924a010a4eb6b210b41 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 3 Oct 2013 17:45:31 -0700 Subject: [PATCH] Do not restart parse - just shift everything as necessary. --- src/libguac/instruction.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libguac/instruction.c b/src/libguac/instruction.c index d34c865c..d4119ba4 100644 --- a/src/libguac/instruction.c +++ b/src/libguac/instruction.c @@ -206,11 +206,23 @@ guac_instruction* guac_instruction_read(guac_socket* socket, /* Shift backward if possible */ if (instr_start != socket->__instructionbuf) { + + int i; + + /* Shift buffer */ + int offset = instr_start - socket->__instructionbuf; memmove(socket->__instructionbuf, instr_start, unparsed_end - instr_start); - unparsed_end -= instr_start - socket->__instructionbuf; - unparsed_start = instr_start = socket->__instructionbuf; - guac_instruction_reset(instruction); + + /* Update tracking pointers */ + unparsed_end -= offset; + unparsed_start -= offset; + instr_start = socket->__instructionbuf; + + /* Update parsed elements, if any */ + for (i=0; i__elementc; i++) + instruction->__elementv[i] -= offset; + } /* Otherwise, no memory to read */