Lua fix reader bug in lzio
When loading a file, Lua may call the reader function again after it
returned end of input
https://www.lua.org/bugs.html#5.1.5-2
Change-Id: Ic2f4d727705a0b8f48ce792f6a9f7af25a503037
diff --git a/apps/plugins/lua/lzio.c b/apps/plugins/lua/lzio.c
index 293edd5..54d5ec4 100644
--- a/apps/plugins/lua/lzio.c
+++ b/apps/plugins/lua/lzio.c
@@ -22,10 +22,15 @@
size_t size;
lua_State *L = z->L;
const char *buff;
+ if (!z->reader)
+ return EOZ;
lua_unlock(L);
buff = z->reader(L, z->data, &size);
lua_lock(L);
- if (buff == NULL || size == 0) return EOZ;
+ if (buff == NULL || size == 0) {
+ z->reader = NULL; /* avoid calling reader function next time */
+ return EOZ;
+ }
z->n = size - 1;
z->p = buff;
return char2int(*(z->p++));