From 3c710f056b683136a342bc5bf88d852717cd0d33 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 17 Feb 2011 15:34:16 -0200 Subject: small bug: may call reader function again after it returned end of input --- lzio.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lzio.c') diff --git a/lzio.c b/lzio.c index a09dbdad..24826f68 100644 --- a/lzio.c +++ b/lzio.c @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp roberto $ +** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp roberto $ ** a generic input stream interface ** See Copyright Notice in lua.h */ @@ -22,10 +22,14 @@ int luaZ_fill (ZIO *z) { size_t size; lua_State *L = z->L; const char *buff; + if (z->eoz) 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->eoz = 1; /* avoid calling reader function next time */ + return EOZ; + } z->n = size - 1; z->p = buff; return char2int(*(z->p++)); @@ -51,6 +55,7 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { z->data = data; z->n = 0; z->p = NULL; + z->eoz = 0; } -- cgit v1.2.3-55-g6feb