1When loading a file, Lua may call the reader function again after it returned end of input. 2 3Fetch from: http://www.lua.org/bugs.html#5.1.5-2 4 5Signed-off-by: Francois Perrad <francois.perrad@gadz.org> 6 7Index: b/src/lzio.c 8=================================================================== 9--- a/src/lzio.c 10+++ b/src/lzio.c 11@@ -22,10 +22,14 @@ 12 size_t size; 13 lua_State *L = z->L; 14 const char *buff; 15+ if (z->eoz) return EOZ; 16 lua_unlock(L); 17 buff = z->reader(L, z->data, &size); 18 lua_lock(L); 19- if (buff == NULL || size == 0) return EOZ; 20+ if (buff == NULL || size == 0) { 21+ z->eoz = 1; /* avoid calling reader function next time */ 22+ return EOZ; 23+ } 24 z->n = size - 1; 25 z->p = buff; 26 return char2int(*(z->p++)); 27@@ -51,6 +55,7 @@ 28 z->data = data; 29 z->n = 0; 30 z->p = NULL; 31+ z->eoz = 0; 32 } 33 34 35Index: b/src/lzio.h 36=================================================================== 37--- a/src/lzio.h 38+++ b/src/lzio.h 39@@ -59,6 +59,7 @@ 40 lua_Reader reader; 41 void* data; /* additional data */ 42 lua_State *L; /* Lua state (for reader) */ 43+ int eoz; /* true if reader has no more data */ 44 }; 45 46 47