diff options
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.140 2014/11/02 19:33:33 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.141 2014/11/21 12:17:33 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -464,9 +464,9 @@ static int test_eof (lua_State *L, FILE *f) { | |||
464 | 464 | ||
465 | static int read_line (lua_State *L, FILE *f, int chop) { | 465 | static int read_line (lua_State *L, FILE *f, int chop) { |
466 | luaL_Buffer b; | 466 | luaL_Buffer b; |
467 | int c; | 467 | int c = '\0'; |
468 | luaL_buffinit(L, &b); | 468 | luaL_buffinit(L, &b); |
469 | for (;;) { | 469 | while (c != EOF && c != '\n') { /* repeat until end of line */ |
470 | char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */ | 470 | char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */ |
471 | int i = 0; | 471 | int i = 0; |
472 | l_lockfile(f); /* no memory errors can happen inside the lock */ | 472 | l_lockfile(f); /* no memory errors can happen inside the lock */ |
@@ -474,8 +474,6 @@ static int read_line (lua_State *L, FILE *f, int chop) { | |||
474 | buff[i++] = c; | 474 | buff[i++] = c; |
475 | l_unlockfile(f); | 475 | l_unlockfile(f); |
476 | luaL_addsize(&b, i); | 476 | luaL_addsize(&b, i); |
477 | if (i < LUAL_BUFFERSIZE) | ||
478 | break; | ||
479 | } | 477 | } |
480 | if (!chop && c == '\n') /* want a newline and have one? */ | 478 | if (!chop && c == '\n') /* want a newline and have one? */ |
481 | luaL_addchar(&b, c); /* add ending newline to result */ | 479 | luaL_addchar(&b, c); /* add ending newline to result */ |