aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ldebug.c16
-rw-r--r--testes/errors.lua7
2 files changed, 17 insertions, 6 deletions
diff --git a/ldebug.c b/ldebug.c
index 603c39fc..8e3657a9 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -638,14 +638,18 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
638 638
639 639
640/* 640/*
641** The subtraction of two potentially unrelated pointers is 641** Check whether pointer 'o' points to some value in the stack
642** not ISO C, but it should not crash a program; the subsequent 642** frame of the current function. Because 'o' may not point to a
643** checks are ISO C and ensure a correct result. 643** value in this stack, we cannot compare it with the region
644** boundaries (undefined behaviour in ISO C).
644*/ 645*/
645static int isinstack (CallInfo *ci, const TValue *o) { 646static int isinstack (CallInfo *ci, const TValue *o) {
646 StkId base = ci->func + 1; 647 StkId pos;
647 ptrdiff_t i = cast(StkId, o) - base; 648 for (pos = ci->func + 1; pos < ci->top; pos++) {
648 return (0 <= i && i < (ci->top - base) && s2v(base + i) == o); 649 if (o == s2v(pos))
650 return 1;
651 }
652 return 0; /* not found */
649} 653}
650 654
651 655
diff --git a/testes/errors.lua b/testes/errors.lua
index 4249f570..fd02806e 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -191,6 +191,13 @@ checkmessage("a = 24 // 0", "divide by zero")
191checkmessage("a = 1 % 0", "'n%0'") 191checkmessage("a = 1 % 0", "'n%0'")
192 192
193 193
194-- type error for an object which is neither in an upvalue nor a register.
195-- The following code will try to index the value 10 that is stored in
196-- the metatable, without moving it to a register.
197checkmessage("local a = setmetatable({}, {__index = 10}).x",
198 "attempt to index a number value")
199
200
194-- numeric for loops 201-- numeric for loops
195checkmessage("for i = {}, 10 do end", "table") 202checkmessage("for i = {}, 10 do end", "table")
196checkmessage("for i = io.stdin, 10 do end", "FILE") 203checkmessage("for i = io.stdin, 10 do end", "FILE")