blob: 5a5d0f27fd8ad04930961d37a573b4adcd15abf5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= <benoit.burnichon@airtag.com>
Date: Tue, 6 Dec 2011 14:23:53 +0100
Subject: [PATCH] io.read("*n", "*n") may return garbage if second read fails.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Comes from http://www.lua.org/bugs.html#5.1.4-8
reported by Roberto on 12 Apr 2010.
Example:
--
print(io.read("*n", "*n")) --<< enter "10 hi"
--> file (0x884420) nil
--
Signed-off-by: Benoît Burnichon <benoit.burnichon@airtag.com>
---
src/liolib.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/src/liolib.c b/src/liolib.c
index e79ed1c..8de2547 100644
--- a/src/liolib.c
+++ b/src/liolib.c
@@ -276,7 +276,10 @@ static int read_number (lua_State *L, FILE *f) {
lua_pushnumber(L, d);
return 1;
}
- else return 0; /* read fails */
+ else {
+ lua_pushnil(L); /* "result" to be removed */
+ return 0; /* read fails */
+ }
}
|