diff options
-rw-r--r-- | stream.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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); |