From 67bdc8dbc90e93b3079886b726157f796ebfd941 Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Wed, 28 Jan 2009 18:39:41 +0000 Subject: [PATCH] Tighten type rules on for loops --- src/core/org/luaj/vm/LuaState.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/org/luaj/vm/LuaState.java b/src/core/org/luaj/vm/LuaState.java index ba2530fb..df93267c 100644 --- a/src/core/org/luaj/vm/LuaState.java +++ b/src/core/org/luaj/vm/LuaState.java @@ -786,9 +786,15 @@ public class LuaState extends Lua { continue; } case LuaState.OP_FORPREP: { - init = this.stack[base + a]; - step = this.stack[base + a + 2]; + init = this.stack[base + a].luaToNumber(); + limit = this.stack[base + a + 1].luaToNumber(); + step = this.stack[base + a + 2].luaToNumber(); + if ( init.isNil() ) error("'for' initial value must be a number"); + if ( limit.isNil() ) error("'for' limit must be a number"); + if ( step.isNil() ) error("'for' step must be a number"); this.stack[base + a] = step.luaBinOpUnknown(Lua.OP_SUB, init); + this.stack[base + a + 1] = limit; + this.stack[base + a + 2] = step; b = LuaState.GETARG_sBx(i); ci.pc += b; continue;