diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-02-17 15:34:16 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-02-17 15:34:16 -0200 |
| commit | 3c710f056b683136a342bc5bf88d852717cd0d33 (patch) | |
| tree | 39faa6d42d6b512d482d6afe0bc01de14ff0315d /lzio.c | |
| parent | c0a865fa54b3c692af3783bd9470b8c0537b77b4 (diff) | |
| download | lua-3c710f056b683136a342bc5bf88d852717cd0d33.tar.gz lua-3c710f056b683136a342bc5bf88d852717cd0d33.tar.bz2 lua-3c710f056b683136a342bc5bf88d852717cd0d33.zip | |
small bug: may call reader function again after it returned end
of input
Diffstat (limited to 'lzio.c')
| -rw-r--r-- | lzio.c | 9 |
1 files changed, 7 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp roberto $ | 2 | ** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp roberto $ |
| 3 | ** a generic input stream interface | 3 | ** a generic input stream interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -22,10 +22,14 @@ int luaZ_fill (ZIO *z) { | |||
| 22 | size_t size; | 22 | size_t size; |
| 23 | lua_State *L = z->L; | 23 | lua_State *L = z->L; |
| 24 | const char *buff; | 24 | const char *buff; |
| 25 | if (z->eoz) return EOZ; | ||
| 25 | lua_unlock(L); | 26 | lua_unlock(L); |
| 26 | buff = z->reader(L, z->data, &size); | 27 | buff = z->reader(L, z->data, &size); |
| 27 | lua_lock(L); | 28 | lua_lock(L); |
| 28 | if (buff == NULL || size == 0) return EOZ; | 29 | if (buff == NULL || size == 0) { |
| 30 | z->eoz = 1; /* avoid calling reader function next time */ | ||
| 31 | return EOZ; | ||
| 32 | } | ||
| 29 | z->n = size - 1; | 33 | z->n = size - 1; |
| 30 | z->p = buff; | 34 | z->p = buff; |
| 31 | return char2int(*(z->p++)); | 35 | return char2int(*(z->p++)); |
| @@ -51,6 +55,7 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { | |||
| 51 | z->data = data; | 55 | z->data = data; |
| 52 | z->n = 0; | 56 | z->n = 0; |
| 53 | z->p = NULL; | 57 | z->p = NULL; |
| 58 | z->eoz = 0; | ||
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | 61 | ||
