summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-03-05 01:09:27 +0100
committerAki <please@ignore.pl>2021-03-05 01:09:27 +0100
commit80faaca56971219c7135e07f1d3eda8c9fb98c19 (patch)
tree32a3cc087cee8bb03d4de96e645e0d83416bbb89
parent13ea99aa41318e144c24bf8843de8100f05ece9c (diff)
downloadplop-80faaca56971219c7135e07f1d3eda8c9fb98c19.zip
plop-80faaca56971219c7135e07f1d3eda8c9fb98c19.tar.gz
plop-80faaca56971219c7135e07f1d3eda8c9fb98c19.tar.bz2
Fixed minor issues in flush and write growth
-rw-r--r--stream.c9
1 files 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);