Browse Source

Lua: Add extra check for k > length inside of __newindex mt function, to avoid setting length on internal null values

Justin Donaldson 9 years ago
parent
commit
65965c6945
1 changed files with 1 additions and 1 deletions
  1. 1 1
      genlua.ml

+ 1 - 1
genlua.ml

@@ -1751,7 +1751,7 @@ let generate com =
 	spr ctx "   setmetatable(tab, {"; newline ctx;
 	spr ctx "   setmetatable(tab, {"; newline ctx;
 	spr ctx "	__index = Array.prototype,"; newline ctx;
 	spr ctx "	__index = Array.prototype,"; newline ctx;
 	spr ctx "	__newindex = function(t,k,v)"; newline ctx;
 	spr ctx "	__newindex = function(t,k,v)"; newline ctx;
-	spr ctx "	    if _G.type(k) == 'number' then"; newline ctx;
+	spr ctx "	    if _G.type(k) == 'number' and k >= length then"; newline ctx;
 	spr ctx "		t.length = k + 1"; newline ctx;
 	spr ctx "		t.length = k + 1"; newline ctx;
 	spr ctx "	    end"; newline ctx;
 	spr ctx "	    end"; newline ctx;
 	spr ctx "	    rawset(t,k,v)"; newline ctx;
 	spr ctx "	    rawset(t,k,v)"; newline ctx;