From b8aaaafb680b08efa8f2c747cec64cec1d3fab90 Mon Sep 17 00:00:00 2001 From: Lorenzo Stanco Date: Wed, 31 Oct 2018 15:57:02 +0100 Subject: [PATCH] Check the type before reusing a NumberValueEntry Fixes #20 --- src/core/org/luaj/vm2/LuaTable.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/org/luaj/vm2/LuaTable.java b/src/core/org/luaj/vm2/LuaTable.java index 054d953d..d95e261c 100644 --- a/src/core/org/luaj/vm2/LuaTable.java +++ b/src/core/org/luaj/vm2/LuaTable.java @@ -1246,13 +1246,14 @@ public class LuaTable extends LuaValue implements Metatable { } public Entry set(LuaValue value) { - LuaValue n = value.tonumber(); - if ( !n.isnil() ) { - this.value = n.todouble(); - return this; - } else { - return new NormalEntry( this.key, value ); + if (value.type() == TNUMBER) { + LuaValue n = value.tonumber(); + if (!n.isnil()) { + this.value = n.todouble(); + return this; + } } + return new NormalEntry( this.key, value ); } public int keyindex( int mask ) {