aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-22 15:32:28 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-22 15:32:28 -0200
commit6af005ec20323defd2a5ead01e2d389462884d04 (patch)
tree68b896e570eb8986e66ed13f3fc547fce00c0e25
parentf8a0fd268e1d23ec180f3af463b21019ce12c29c (diff)
downloadlua-6af005ec20323defd2a5ead01e2d389462884d04.tar.gz
lua-6af005ec20323defd2a5ead01e2d389462884d04.tar.bz2
lua-6af005ec20323defd2a5ead01e2d389462884d04.zip
bug: when `read' fails it must return nil (and not no value)
-rw-r--r--bugs5
-rw-r--r--liolib.c21
2 files changed, 16 insertions, 10 deletions
diff --git a/bugs b/bugs
index 1aff4595..a1391524 100644
--- a/bugs
+++ b/bugs
@@ -245,3 +245,8 @@ Wed Nov 29 09:51:44 EDT 2000
245>> parser does not accept a `;' after a `return' 245>> parser does not accept a `;' after a `return'
246(by lhf; since 4.0b) 246(by lhf; since 4.0b)
247 247
248** liolib.c
249Fri Dec 22 15:30:42 EDT 2000
250>> when `read' fails it must return nil (and not no value)
251(by cassino; since at least 3.1)
252
diff --git a/liolib.c b/liolib.c
index 6cb555af..354dc849 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.94 2000/12/18 13:42:19 roberto Exp roberto $ 2** $Id: liolib.c,v 1.95 2000/12/22 16:57:13 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*/
@@ -318,6 +318,7 @@ static int io_read (lua_State *L) {
318 IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); 318 IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
319 int lastarg = lua_gettop(L) - 1; 319 int lastarg = lua_gettop(L) - 1;
320 int firstarg = 1; 320 int firstarg = 1;
321 int success;
321 FILE *f = gethandle(L, ctrl, firstarg); 322 FILE *f = gethandle(L, ctrl, firstarg);
322 int n; 323 int n;
323 if (f) firstarg++; 324 if (f) firstarg++;
@@ -330,8 +331,8 @@ static int io_read (lua_State *L) {
330 } 331 }
331 else /* ensure stack space for all results and for auxlib's buffer */ 332 else /* ensure stack space for all results and for auxlib's buffer */
332 luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments"); 333 luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments");
333 for (n = firstarg; n<=lastarg; n++) { 334 success = 1;
334 int success; 335 for (n = firstarg; n<=lastarg && success; n++) {
335 if (lua_isnumber(L, n)) 336 if (lua_isnumber(L, n))
336 success = read_chars(L, f, (size_t)lua_tonumber(L, n)); 337 success = read_chars(L, f, (size_t)lua_tonumber(L, n));
337 else { 338 else {
@@ -343,8 +344,8 @@ static int io_read (lua_State *L) {
343 else { 344 else {
344 switch (p[1]) { 345 switch (p[1]) {
345 case 'n': /* number */ 346 case 'n': /* number */
346 if (!read_number(L, f)) goto endloop; /* read fails */ 347 success = read_number(L, f);
347 continue; /* number is already pushed; avoid the "pushstring" */ 348 break;
348 case 'l': /* line */ 349 case 'l': /* line */
349 success = read_line(L, f); 350 success = read_line(L, f);
350 break; 351 break;
@@ -361,11 +362,11 @@ static int io_read (lua_State *L) {
361 } 362 }
362 } 363 }
363 } 364 }
364 if (!success) { 365 }
365 lua_pop(L, 1); /* remove last result */ 366 if (!success) {
366 break; /* read fails */ 367 lua_pop(L, 1); /* remove last result */
367 } 368 lua_pushnil(L); /* push nil instead */
368 } endloop: 369 }
369 return n - firstarg; 370 return n - firstarg;
370} 371}
371 372