summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-11-09 11:49:22 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2018-11-15 11:20:54 +0100
commit03718bdb76a3d9dd9a28caf862d590e78a6739aa (patch)
tree6e712eccfe6876238f88d27eb56ae928f25fb59d
parentb69faf0bcc5ddca1d88b1a7ab47bcbbc6dbb9af1 (diff)
downloadrockbox-03718bdb76a3d9dd9a28caf862d590e78a6739aa.tar.gz
rockbox-03718bdb76a3d9dd9a28caf862d590e78a6739aa.zip
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
-rw-r--r--apps/plugins/lua/lzio.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/apps/plugins/lua/lzio.c b/apps/plugins/lua/lzio.c
index 293edd59b0..54d5ec4741 100644
--- a/apps/plugins/lua/lzio.c
+++ b/apps/plugins/lua/lzio.c
@@ -22,10 +22,15 @@ int luaZ_fill (ZIO *z) {
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++));