From 80faaca56971219c7135e07f1d3eda8c9fb98c19 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 5 Mar 2021 01:09:27 +0100 Subject: Fixed minor issues in flush and write growth --- stream.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stream.c b/stream.c index f0c6723..f5dab24 100644 --- a/stream.c +++ b/stream.c @@ -311,11 +311,12 @@ int stream_write(lua_State * L) { size_t data_length; const char * data = lua_tolstring(L, i, &data_length); - const int free_space = s->out.allocated - s->out.length; + int free_space = s->out.allocated - s->out.length; while (free_space < (int) data_length) { grow(L, &s->out); + free_space = s->out.allocated - s->out.length; } if (free_space >= (int) data_length) @@ -379,7 +380,11 @@ int stream_flushk(lua_State * L, const int status, lua_KContext ctx) } else { - s->out.length -= bytes_written; + s->out.length = s->out.length - bytes_written; + if (0 < s->out.length) + { + memmove(s->out.data, &s->out.data[bytes_written], s->out.length); + } } lua_pop(L, 1); -- cgit v1.1